I am trying to write a where clause in Linq that matches on a date. The values for date is contained in a nested object. 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. 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()
。
日期和位置之间没有联系-我设法通过使用字典类来解决此问题,然后匹配日期!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.