c# - Entity Framework 4 Loading Reference Exception -


i'm having troubles loading reference parent object in entity framework 4. due lazy loading reference parent object (condition) not loaded on child object (discountlevel), try load with:

if(!this.conditionreference.isloaded) this.conditionreference.load(); 

but throws following exception:

the entity reference not loaded because not attached objectcontext

so if try attach existing child object (discountlevel) object context (and load parent reference afterwards):

context.attachto("tbldiscountlevel", this); 

i following exception:

an object same key exists in objectstatemanager. existing object in detached state. object can added objectstatemanager again if in added state.

i feel i'm doing wrong in first place, can't figure out what. every on topic appreciated. let me know if need additional information!

i stumbled upon problem , didn't have code above: there few calculations in various overwritten onchange-methods in discountlevel fail if they're called - in case on initial loading db. resulted child object not initialized - appearing not loaded @ outside.

implementing simple bool-variable supressed execution of onchange-methods on initial load made work expected. there might more elegant solution features entity framework provides, worked me.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -