C# – Entity Framework Include() strongly typed

asp.netcentity-framework

Is there a way to make this strongly typed using the System.Data.Entity.Include method? In the method below Escalation is a ICollection<>.

public IEnumerable<EscalationType> GetAllTypes() {
  Database.Configuration.LazyLoadingEnabled = false;
  return Database.EscalationTypes
    .Include("Escalation")
    .Include("Escalation.Primary")
    .Include("Escalation.Backup")
    .Include("Escalation.Primary.ContactInformation")
    .Include("Escalation.Backup.ContactInformation").ToList();
}

Best Answer

This is already available in Entity Framework 4.1.

See here for a reference for how to use the include feature, it also shows how to include multiple levels: http://msdn.microsoft.com/en-us/library/gg671236(VS.103).aspx

The strongly typed Include() method is an extension method so you have to remember to declare the using System.Data.Entity; statement.