实体框架包括()强类型 [英] Entity Framework Include() strongly typed

查看:102
本文介绍了实体框架包括()强类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法,使这种强烈的使用方法System.Data.Entity.Include类型?在下面升级的方法是一个的ICollection&下;>

 公开的IEnumerable< EscalationType> GetAllTypes(){
  Database.Configuration.LazyLoadingEnabled = FALSE;
  返回Database.EscalationTypes
    .INCLUDE(升级)
    .INCLUDE(Escalation.Primary)
    .INCLUDE(Escalation.Backup)
    .INCLUDE(Escalation.Primary.ContactInformation)
    .INCLUDE(Escalation.Backup.ContactInformation)了ToList()。
}


解决方案

这是已经可以在实体框架4.1。

在这里看到对如何使用功能包括一个参考,它也显示了如何包含多个层次:<一href=\"http://msdn.microsoft.com/en-us/library/gg671236%28VS.103%29.aspx\">http://msdn.microsoft.com/en-us/library/gg671236(VS.103).aspx

强类型包括()方法是一个扩展方法,所以你必须记住要申报使用System.Data.Entity的; 语句。

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();
}

解决方案

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.

这篇关于实体框架包括()强类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆