[英]Unable to write a Where Clause with Linq where data contains an array
我试图在Linq中写一个匹配日期的where子句。 date的值包含在嵌套对象中。 我的意思是,包含日期的对象具有开始和结束两个元素。 我收到两个错误消息:
我的代码是:
var locationName = from relocate in relocations where **relocate.Relocations.
Where(c=>c.TimeIntervals.Select(d=>d.Start==sh.StartTime.Date))**
select relocate.Relocations.Select(a=>a.Path.Items.
Select(b=>b.DisplayString.Skip(4).SingleOrDefault()));
它是在双**之间的位。
请帮忙!!!
您的relocate.Relocations.Where
返回IEnumerable。 您需要将其与某些东西进行比较(相交),以便结果评估为布尔值。
也许像这样:
relocate.Relocations.Where(...).Any()
var locationName = from relocate in relocations where **relocate.Relocations.
Where(c=>c.TimeIntervals.Select(d=>d.Start==sh.StartTime.Date).Any()).Any()**
select relocate.Relocations.Select(a=>a.Path.Items.
Select(b=>b.DisplayString.Skip(4).SingleOrDefault()));
我认为您只需在语句末尾添加First()
或FirstOrDefault()
。
日期和位置之间没有联系-我设法通过使用字典类来解决此问题,然后匹配日期!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.