hku*_*uay 6 lazy-loading dynamic-proxy entity-framework-6
我在某些操作中通过反射使用类属性,因此在使用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;}
}
Run Code Online (Sandbox Code Playgroud)
看起来您正在寻找DbReferenceEntry <TEntity,TProperty> .IsLoaded或DbReferenceEntry.IsLoaded属性:
if (context.Entry(oCustomer).Reference(e => e.Location).IsLoaded)
Run Code Online (Sandbox Code Playgroud)
要么
if (context.Entry(oCustomer).Reference("Location").IsLoaded)
Run Code Online (Sandbox Code Playgroud)
对于集合类型导航属性,只需使用.Collection而不是.Reference.
| 归档时间: |
|
| 查看次数: |
1310 次 |
| 最近记录: |