Check Lazy Load property has loaded in EF6

dynamic-proxy entity-framework-6 lazy-loading

Question

I'm using class properties by reflection in some operations so when using DynamicProxy instance it causes to load entire DB. (700+ classes are related with each other).

Is it possible to check if lazy load property loaded or not? Disabling dynamic proxy generation (ProxyCreationEnabled = false) is not usable in my case.

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;}
}
1
6
6/6/2016 6:38:26 AM

Accepted Answer

Looks like you are seeking for DbReferenceEntry<TEntity, TProperty>.IsLoaded or DbReferenceEntry.IsLoaded property:

if (context.Entry(oCustomer).Reference(e => e.Location).IsLoaded)

or

if (context.Entry(oCustomer).Reference("Location").IsLoaded)

For collection type navigation properties, just use .Collection instead of .Reference.

7
6/6/2016 8:03:48 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow