开发者

Deriving 2 times on Entity Framework

Let's say we have tables named A, B, C . C derived from B and B derived from A. So if i want to get C table, OfType(C) will bring result as expected. But if i wrot开发者_如何学运维e OfType(B) result will include entries of table C.

How i could get result just for B ? Is there better solution of Entity Framework ?


There's probably a better/faster/sexier way to do this, but you could always do something with LINQ:

var results = yourCollectionOfBsAndCs.Where(o => !(o is C));


If we try to exclude inherited classes so we have to write all of them and we should to update our code if there will be another inherited classes in future. So instead of them this code will be better solution.

//collection include classes A and inherited classes from A.
collection.Where(o => o.GetType() == typeof(A)); 
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜