entity framework包含()强types

有没有办法使这个强types使用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中可用。

有关如何使用includefunction的参考资料,请参阅这里,它还显示如何包含多个级别: http : //msdn.microsoft.com/en-us/library/gg671236(VS.103).aspx

强types的Include()方法是一个扩展方法,所以你必须记住声明using System.Data.Entity; 声明。

信贷去Joe Ferner :

 public static class ObjectQueryExtensionMethods { public static ObjectQuery<T> Include<T>(this ObjectQuery<T> query, Expression<Func<T, object>> exp) { Expression body = exp.Body; MemberExpression memberExpression = (MemberExpression)exp.Body; string path = GetIncludePath(memberExpression); return query.Include(path); } private static string GetIncludePath(MemberExpression memberExpression) { string path = ""; if (memberExpression.Expression is MemberExpression) { path = GetIncludePath((MemberExpression)memberExpression.Expression) + "."; } PropertyInfo propertyInfo = (PropertyInfo)memberExpression.Member; return path + propertyInfo.Name; } } 
 ctx.Users.Include(u => u.Order.Item)