Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework: Eager Loading Navigation Properties of Inherited Entities

I am trying to eager load my entire graph and it looks like the following:

public class WorkoutProgram
{
    public Schedule Schedule { get; set; }
}

public class Schedule
{
    public ICollection<DayBase> Days { get; set; }
}

public abstract class DayBase
{
}

public class TrainingDay : DayBase
{
    public ICollection<Exercise> Exercises { get; set; }
}

context.WorkoutPrograms.Include("Schedule.Days.Exercises");

Obviously, not all Schedule.Days are TrainingDays, so I get a runtime error because of the path including Exercises.

Am I missing a configuration here, or do I need to resort to lazy loading (which I hope not).

Thanks

like image 534
Marco Avatar asked Sep 01 '11 13:09

Marco


1 Answers

Looks like many developers are having pain of this issue, including me.

Please cast your vote!!!

like image 146
Shimmy Weitzhandler Avatar answered Oct 24 '22 23:10

Shimmy Weitzhandler