How to avoid polymorphic behaviour in Entity Framework TPT Inheritance in order to query base type efficiently

吃可爱长大的小学妹 提交于 2019-12-05 15:24:35

Is there a way to construct a query to force EF to only return the base type instead of the polymorphic type which results in too many joins and horrible performance?

Generally no. You have mapped inheritance and if you want to return instances of Item, EF must always return correct type => it needs those joins. EF also doesn't allow mapping the same table multiple times so you cannot have in the same mapping the Item mapped again as another POCO.

In theory you should be able to query Items and project to your non mapped POCO class only properties you want from the base class. Unfortunately this didn't work in .NET 4.0 - EF still performed joins. You can try this with .NET 4.5 and EF 5.0 where this issue should be solved.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!