0

以下查询在我展开导航属性Schedules时工作正常,该属性与AssociatedListing属性具有多对一的关系:

from la in ListingAssociations.Expand("AssociatedListing").Expand("AssociatedListing/Schedules")
where la.ListingId==60
select la

在结果中,我可以看到与每个AssociatedListing对象对应的多个Schedule对象。这很好。

但是,当我尝试在任何Schedules字段上添加过滤器时:

from la in ListingAssociations.Expand("AssociatedListing").Expand("AssociatedListing/Schedules")
where la.ListingId==60 && la.AssociatedListing.Schedules.StartDate > DateTime.Today
select la

我得到错误:

“‘System.Collections.ObjectModel.Collection’不包含‘StartDate’的定义,并且找不到接受‘System.Collections.ObjectModel.Collection’类型的第一个参数的扩展方法‘StartDate’......”。

所以我猜问题是StartDateSchedule类的一个字段,而“ Schedule ”导航属性是Schedule对象的集合,因此Schedules.StartDate没有任何意义。但是在这种多对一的情况下,必须有某种方法来指定过滤器。如何?

任何帮助将不胜感激!

4

1 回答 1

2

从此更改您的where子句:

where la.ListingId==60 
   && la.AssociatedListing.Schedules.StartDate > DateTime.Today

对此:

where la.ListingId==60 
   && la.AssociatedListing.Schedules.All(x => x.StartDate > DateTime.Today)

如果您希望任何计划的开始日期都大于今天(而不是过滤到所有计划的开始日期),请更改AllAny.

于 2011-02-18T05:38:38.533 回答