Entity Framework 4.1 eager loading - on abstract classes
I'm using EF 4.1 at Code First approach. I have an abstract class:
public abstract class Base
{
}
And two dereived classes:
public Class Derived1 : Base
{
public Division division{ get; set; }
}
public Class Derived2 : Base
{
public Brand brand{ get; set; }
}
At last, I have a query that selects a list of the Base class, and i want to perform eager loading, but i don't know who my derived classes are:
using (var db = new MyContext())
{
var lst = db.Base.Include(WHAT SHOULD I WRITE HERE).ToList();
}开发者_开发百科
Any Ideas?
You must do this:
var lst = db.Base.OfType<Derived1>().Include(d => division)
.Union(
db.Base.OfType<Derived2>().Include(d => d.brand))
.ToList();
精彩评论