Entity Framework 4.3 - High Load Polymorphic Query

I have a model that looks something like this:

public abstract class Parent
{
    public int Id { get; set; }
}

public class Child11 : Parent
{}

public class Child2 : Parent
{
    public virtual Dependency Dependency { get; set; }
}

public class Dependency
{
    public int Id { get; set; }
    public virtual ICollection<Child2> Children { get; set; }
}

      

I'm trying to figure out who is writing a Linq query that loads all parent and eager loads. Dependency on all children. Is it possible? I've tried every combination of Linq statements I could think of and had no success.

+3


source to share


1 answer


If you only need to load child2, you can use:

var child2 = context.Parents
                    .OfType<Child2>()
                    .Include(c => c.Dependency)
                    .ToList();

      



If you also need to load all the other derived types, you will most likely need to use a second query or try to create some kind of union. Polymorphic queries in EF don't work very well with heavy load.

+3


source







All Articles