簡體   English   中英

無法使用Linq編寫Where子句,其中數據包含數組

[英]Unable to write a Where Clause with Linq where data contains an array

我試圖在Linq中寫一個匹配日期的where子句。 date的值包含在嵌套對象中。 我的意思是,包含日期的對象具有開始和結束兩個元素。 我收到兩個錯誤消息:

  1. 無法將System.Collections.Generic.IEnumerable隱式轉換為bool
  2. 無法將lambda表達式轉換為委托類型System.Func,因為塊中的某些返回類型不能隱式轉換為委托返回類型

我的代碼是:

 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM