.net - Does ObjectContext keep track of already fetched entities when refetching them -


  1. i fetch object database (poco object proxy)
  2. i modify property without saving changes
  3. i fetch later on again database (i use same object context)
  4. what value of property?

for example if have object context collection users result of following:

objectcontext o = ....; user u = o.users.first(u=>u.id == 1); console.writeline(u.lastname); // 'test' example u.lastname = 'somethingelse'; u  = o.users.first(u=>u.id == 1); console.writeline(u.lastname); // result?? 

if result of last statement not string "somethingelse" there way achieve funcionality?

that core feature of orm tools called identity map pattern. entity unique key can materialized once per context second query default use same instance without changing values.

you can force query refresh values either:

objectcontext o = ....; user u = o.users.first(u=>u.id == 1); console.writeline(u.lastname); // 'test' example u.lastname = 'somethingelse'; o.users.mergeoption = mergeoption.overwritechagnes; // here change behavior u  = o.users.first(u=>u.id == 1); console.writeline(u.lastname); // result 'test' again 

or reloading entity itself:

objectcontext o = ....; user u = o.users.first(u=>u.id == 1); console.writeline(u.lastname); // 'test' example u.lastname = 'somethingelse'; o.refresh(refreshmode.storewins, u); // here reload entity values database console.writeline(u.lastname); // result 'test' again     

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -