有沒有辦法使用System.Data.Entity.Include方法來強制類型化?在下面的方法中,升級是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();
}
如果你有EFv4.1,你不必使用魔術字符串:http://stackoverflow.com/questions/5247324/ef-code-first-ctp5-using-include-method-with-many-to -many-table/5247423#5247423 – 2011-05-23 21:21:39
這也可能會讓你感興趣:http://stackoverflow.com/questions/5376421/ef-including-other-entities-generic-repository-pattern/5376637#5376637 – 2011-05-23 21:24:17