c# - Entity Framework Include() 强类型

标签 c# asp.net entity-framework

有没有办法使用 System.Data.Entity.Include 方法使其成为强类型?在下面的方法中,Escalation 是一个 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();
}

最佳答案

这在 Entity Framework 4.1 中已经可用。

有关如何使用包含功能的引用,请参阅此处,它还展示了如何包含多个级别:http://msdn.microsoft.com/en-us/library/gg671236(VS.103).aspx

强类型 Include() 方法是一种扩展方法,因此您必须记住声明 using System.Data.Entity; 语句。

关于c# - Entity Framework Include() 强类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6102909/

相关文章:

c# - 无法将图像渲染到 HttpContext.Response.OutputStream

asp.net - 无法在 Web 配置文件中设置输出缓存设置

C# Entity Framework 在查询中使用模型中的类比使用匿名类慢

c# - 删除过多的 try-catch block

c# - 无法在桌面应用程序后面的代码中绑定(bind) GridView

c# - KOFAX 位图文件 : How can I open them?

c# - 在 EntityFramework 中删除具有相关实体的实体

c# - 为什么 Java 或 C# 中不允许多重继承?

asp.net - 如何以编程方式替换 ASP.NET GridView 中的 HyperLinkField

c# - 在 DbContext 中访问 HttpContext.Current.User.Identity.Name