Quantcast
Channel: Entity Framework
Viewing all articles
Browse latest Browse all 10318

New Post: Eager Loading (using Include) for abstract class

$
0
0

I see a lot of question but no real answer as for the way/support we can have using Entity Framework and abstract class (mainly usage of inheritance and classes).

assuming i have:

Employee:

id
Name 

Manager :subclass of Employee

 Projects (collection of projects he manage)

Developer :subclass of Employee

Languages (collection of languages he knows)

 

i need to accomplish two things:

1. assuming i want to find employee by ID and i want to make sure i eager load the navigation properties

2. i want to return all employees and i want to make sure i eager load the navigation properties

in both options i want to use the default lazy loading and ONLY eager load what i choose.

 

Writing "DBctx.Employees.include(m=>m.Projects).include(d=>d.Languages)" is not supported since the abstract class doesn't have the properties (as the first problem).

if i add OfType i need to union with all known types and this is a problem for me since its not robust enough and also during run time will cause a problem while trying to execute since it will try to find navigation property for the abstract again

Also adding OfType impact my find statement which means that i need to do multiple find (multiple calls) 

I find it a bit weird that there is no solid solution for it as of now


Viewing all articles
Browse latest Browse all 10318

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>