开发者

Checking Parent Type TPT EF4

I have a TPT scenario in EF4 with an abstract base class.

I need to wite a linq query against a collection of children types to get the value from a field of one type of parent.

eg.

ThisChild = Children.Where(c. => c.Parent.OfType<Mother>.Jewe开发者_运维百科lleryCollection > 10).FirstOrDefault();

In this case, Parent is the abstract class with Mother being a type of Parent. Mother is the only type that has a JewelleryCollection field.

The example above breaks because you cannot use the .OfType<> method. How can I best structure this query?

Thanks.


Because you are running the query on ObservableCollection it is Linq-to-objects where you can simply use conversion:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜