[英]Unable to write a Where Clause with Linq where data contains an array
I am trying to write a where clause in Linq that matches on a date. 我试图在Linq中写一个匹配日期的where子句。 The values for date is contained in a nested object.
date的值包含在嵌套对象中。 What I mean is that the object that contains date has two elements start and finish.
我的意思是,包含日期的对象具有开始和结束两个元素。 I am getting two error messages:
我收到两个错误消息:
My code is: 我的代码是:
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()));
It is the bit which is between the double **. 它是在双**之间的位。
Please help!!! 请帮忙!!!
Your relocate.Relocations.Where
returns IEnumerable. 您的
relocate.Relocations.Where
返回IEnumerable。 You need to compare (intersect) that with something, such that result evaluates to a boolean. 您需要将其与某些东西进行比较(相交),以便结果评估为布尔值。
Perhaps like this: 也许像这样:
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.