DBContext lazyloadingenabled set to true still loads related objects by default

LazyLoadingEnabled is specifically set to true to prevent the loading of related objects in the context that I am using.

The drug class has a list of objects with drug identification.

public class Drug
{
   public virtual List<DrugIdentity> DrugIdentities { get; set; }
}

The specific configuration for the class establishes a key and hasmany relationship if I would like to include a related object to load.

public DrugConfiguration()
    {
        this.HasKey(d => d.DrugID);
        this.HasMany(d => d.DrugIdentities).WithOptional(d => d.Drug).Map(d => d.MapKey("DrugID"));
    }

When the Drug context is loaded using the linq query, the object indicates that it contains properties associated with it, if it is not.

context.Configuration.LazyLoadingEnabled = true;

                    var drugs = from d in context.Drug
                                where d.Active == true
                                select d;

medicines [0]. Disadvantages Count = 1

I would expect drugs [0] .DrugIdentities to be NULL since lazyloading was set to true?

+5
source share
2

ProxyCreationEnabled = false, LazyLoadingEnabled = true.

, . Drugs NULL DrugEntities. DrugEntities, Include .

var queryDrug = from d in context.Drug
                                where d.Active == true
                                select d;

                var drugresults = from d in context.Drug.Include(e => e.DrugIdentities)
                                  where d.Active == true
                                  select d;
+2

All Articles