c# - Must not Entity Framework update some Fk properties automatically? Yes, he does, but sometimes not. Why? -


i have read this question , understand that.

let's have tow entities , have 1 0 or 1 relatinship. let's have such code:

 myfirstentity.primarykey = 5;  mycontext.entry(myfirstentity).state = system.data.entitystate.unchanged; 

after second line, myfirstentity.mysecondentity.primarykey value 5.

so, ok.

but, not wokring if make changes reversely:

 mysecondentity.primarykey = 5;  mycontext.entry(mysecondentity).state = system.data.entitystate.unchanged; 

after second line, mysecondentity.myfirstentity.pk value still 0.

entity framework retrieve entities database not automatically load properties exemple if lazy loading "off" (if property not virtual).

also, if change id of property, have save changes. given code, don't know how retrieved entities, tracked ?

if entities not tracked, have manually assign value of fk.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -