2011-05-09 64 views
0

我在EF4中有一個抽象基類的TPT場景。檢查父類型TPT EF4

我需要對一個子類型的集合進行linq查詢以從一種父類型的字段中獲取值。

例如。

ThisChild = Children.Where(c. => c.Parent.OfType<Mother>.JewelleryCollection > 10).FirstOrDefault(); 

在這種情況下,Parent是抽象類,Mother是父類型。母親是唯一擁有JewelleryCollection字段的類型。

上面的示例中斷,因爲您不能使用.OfType方法。我怎樣才能最好地構造這個查詢?

謝謝。

+0

什麼是'Children'? – 2011-05-09 11:59:42

+0

ObservableCollection Children = new ObservableCollection (); – yimbot 2011-05-09 12:01:34

回答

0

因爲你在ObservableCollection運行查詢,這是Linq到對象,你可以簡單地使用轉換:

ThisChild = Children.FirstOrDefault(c => 
    (c.Parent is Mother) && (((Mother)c.Parent).JewelleryCollection > 10));