LazyLoadingEnabled 专门设置为 true 以防止相关实体在我正在使用的上下文中加载。
药物类别中有一个药物识别对象列表。
public class Drug
{
public virtual List<DrugIdentity> DrugIdentities { get; set; }
}
如果我想包含要加载的相关实体,则该类的特定配置会设置键和 hasmany 关系。
public DrugConfiguration()
{
this.HasKey(d => d.DrugID);
this.HasMany(d => d.DrugIdentities).WithOptional(d => d.Drug).Map(d => d.MapKey("DrugID"));
}
当使用 linq 查询加载药物上下文时,对象显示它不应该包含相关的 DrugIdentities。
context.Configuration.LazyLoadingEnabled = true;
var drugs = from d in context.Drug
where d.Active == true
select d;
药物[0].DrugIdentities 计数 = 1
我希望 drug[0].DrugIdentities 等于 NULL,因为延迟加载设置为 true?
要禁用延迟加载,请将 LazyLoadingEnabled 设置为 false 而不是 true。看相关数据的延迟加载、急切加载和显式加载 in
http://www.asp.net/mvc/tutorials/getting-started-with-ef-using-mvc/reading-lated-data-with-the-entity-framework-in-an-asp-net-mvc-应用
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)