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));
精彩评论