entity framework 4 - which is the difference betwwen this two ways to refresh the dbContext? -
i using ef 4.4 , update many entities, other user can modified many of entities first user modified. concurrency exception. other case first user tries add many new registers , other user added of them meanwhile. have exception exists of registers (unique constraint).
i ensure first user finish operation add registers no exists yet (add entities except entities added second user).
to that, need update entities in dbcontext see there @ least 2 options.
first, in catch when capture update exception, can do:
ex.entries.single().reload();
the second option is:
mycontext.entry<mytable>(instance).reload();
i guess second option refreshes entity use parameter, if problem need refresh many entities, how can that?
what first option, single().reload
?
when do
ex.entries.single().reload();
you sure offending entity refreshed. taking 1 , (single
) entity dbupdateconcurrencyexception.entries
not saved database (in case of concurrency exception one).
when do
mycontext.entry(instance).reload();
you not sure refresh right entity unless know 1 entity had changes before savechanges
called. if save entity child entities 1 of them can cause concurrency problem.
Comments
Post a Comment