.net - Does ObjectContext keep track of already fetched entities when refetching them -
- i fetch object database (poco object proxy)
- i modify property without saving changes
- i fetch later on again database (i use same object context)
- 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
Post a Comment