[英]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.