我在某些操作中通过反射使用类属性,因此在使用DynamicProxy实例时,它会导致加载整个数据库。(700多个类相互关联)。
是否可以检查是否加载了惰性加载属性?ProxyCreationEnabled = false
在我的情况下,无法使用动态代理生成()。
Customer oCustomer = context.get(1);
if(oCustomer.Location.HasLoaded)
do smt..
public class Customer
{
public decimal? Id {get; set;}
public virtual CustomerLocation Location{get; set;}
}
public class CustomerLocation
{
public decimal? Id {get; set;}
public string Detail {get; set;}
}
看起来您正在寻找DbReferenceEntry <TEntity,TProperty> .IsLoaded或DbReferenceEntry.IsLoaded属性:
if (context.Entry(oCustomer).Reference(e => e.Location).IsLoaded)
或者
if (context.Entry(oCustomer).Reference("Location").IsLoaded)
对于集合类型的导航属性,只需使用.Collection
代替.Reference
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句