0

次のクエリは、 AssociatedListingプロパティと多対1の関係にあるナビゲーション プロパティSchedulesを展開した場合に正常に機能します。

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

結果には、各AssociatedListingオブジェクトに対応する複数のScheduleオブジェクトが表示されます。これはいい。

ただし、スケジュールフィールドのいずれかにフィルターを追加しようとすると、次のようになります。

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' が見つかりませんでした...」.

問題は、StartDateがScheduleクラスのフィールドであり、「 Schedules」ナビゲーション プロパティがScheduleオブジェクトのコレクションであるSchedules.StartDateため、意味をなさないことだと思います。しかし、この多対 1 の状況でフィルターを指定する何らかの方法が必要です。どのように?

どんな助けでも大歓迎です!

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 に答える