繁体   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