Entity Framework with Proxy Creation and Lazy Loading disabled is still loading child objects -
i'm having issues entity framework using pocos , hope can tell me @ high level if behaviour i'm seeing expected or need dig deeper why it's happening.
i have class customer
, customertype
, customer
has property type
(of type customertype
indicating type) , customertype
has property customers
collection of customer
s (all customer
s have type) these navigation properties on both ends of association, resulting in poco code like:
public partial class customer { public int id { get; set; } public string name { get; set; } public int typeid { get; set; } public customertype type { get; set; } } public partial class customertype { public customertype() { this.customers = new hashset<customertype>(); } public int id { get; set; } public string typename { get; set; } public virtual icollection<customer> customers { get; set; } }
i have turned off proxy creation , lazyloading (i.e. both dbcontext.configuration.proxycreationenabled=false
, dbcontext.configuration.lazyloadingenabled=false
) because make serialization pain.
as expected when instances customer
set, type
property on them null default.
but if instances customer
set .include("type")
not loading type
properties, it's loading children - i.e. collection of customer
s on each of these.
is expected?
it semi expected. include extension affects sql run. customertypes loaded (by virtue of being included in customer query) built object tree according customertype.parentid column.
so if fluke both parent , child loaded in same query, child stuffed parent.
Comments
Post a Comment