我有以下对象
public Cell {
public string CategoryId {get; set;}
public DateTime FromTime {get; set}
public DateTime ToTime {get; set}
}
我有一个名为 Item 的数据库表,如下所示:
Item
-------------------------
CategoryId LastUpdated
现在在代码中,我有一个List<Cell> ToBeFetchedFromDB
包含多个 Cell 的 Cell 列表,假设列表包含Foo
and Bar
,我想动态构建这样的查询,BY INTERATING THROUGH THE COLLECTION ToBeFetchedFromDB WITHIN MY LINQ TO SQL QUERY
而不是静态构建查询:
from x in Item
where x.CategoryId == Foo.CategoryId && Foo.FromTime < x.LastUpdated < Foo.ToTime
|| x.CategoryId == Bar.CategoryId && Bar.FromTime < x.LastUpdated < Bar.ToTime
select x
我一直在尝试,但无法弄清楚:(
多谢你们!