Entity Framework, Inheritance, eager loading of association

Consider the following three objects:

Person:

string Name

Developer : Person

List<Skill> Skills

Skill:

Name

ID

I thought that in this simple inheritance I would be able to eagerly load the associated Skills of the developers  if any in the list, by doing the following:

var people = (FROM p in Db.people.include((dev as Developer) => dev.Skills) select p).ToList();

Or Maybe just using string based ‘include(“Skills”) ‘

But this simply doesn’t work, in term of no support for such syntax or failure in runtime (not finding skills)

The only method I found to resolve this is to:

var developers = (FROM p in Db.people.OfType<Developer>().include(dev =>dev.Skills) select p).ToList();

var people = (FROM p in Db.people WHERE !(p is Developer) select p).ToList();

var result = people.union(developers);

very ugly since I need to exclude the special entries but working.

 

This case was raised long time ago and was rejected by M$…. here

Entity Framework, Inheritance, eager loading of association Entity Framework, Inheritance, eager loading of association Reviewed by Ran Davidovitz on 11:53 PM Rating: 5

No comments:

Powered by Blogger.