我在EF4中有一个带有抽象基类的TPT场景。
我需要对一组子类型进行linq查询,以从一种父类型的字段中获取值。
例如
ThisChild = Children.Where(c. => c.Parent.OfType<Mother>.JewelleryCollection > 10).FirstOrDefault();
在这种情况下,Parent是抽象类,Mother是一种Parent类型。母亲是唯一拥有JewelleryCollection领域的类型。
上面的示例因为您无法使用.OfType&lt;&gt;而中断方法。如何才能最好地构建此查询?
感谢。
答案 0 :(得分:0)
因为您正在ObservableCollection
上运行查询,所以您只需使用转换即Linq-to-objects:
ThisChild = Children.FirstOrDefault(c =>
(c.Parent is Mother) && (((Mother)c.Parent).JewelleryCollection > 10));