Entity Framework DBContext navigation property loaded by different query? -


i have 2 entities, user , messages. load messages , not user message belongs.

this works not include related entity in linq query. doesn't work if load user separately query string user (the name).

i using ef 6.1.0, poco without proxy generation , wcf services pass data. unwanted navigation property value transferred accidentally.

var message = context.messages.firstordefault(m => m.id == 123);  var user = contect.users.firstordefault(u => u.id = 456);  var message_username_composition = new m_u_c{ m = message, username = user.name };  return message_username_composition; 

in situation have navigation property (user) of message loaded not so.

disabling lazyloading doesn't help, using separate context solves problem.

is there way other using 2 contexts?

is design?

i not manually set navigation properties null fix this, because may forgotten, because 1 did not realize behavior.

you'll have disable lazy-load , use asnotracking() follows:

ctx.configuration.lazyloadingenabled = false; var message = context.messages.asnotracking().firstordefault(m => m.id == 123); 

Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -