This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I have stored procedure that updates table rows. When i requery updated rows i get old data. Code example: using (UnitOfWork unitOfWork = context.CreateUnitOfWork()) { var data = unitOfWork.TestEntities.ToList(); // getting initial data unitOfWork.UpdateTestEntities(); // update initial data through stored procedure data = unitOfWork.TestEntities.ToList(); // requering updated data (initial data returned) } |
|
|
How can i get updated data?
|
|
|
The unit of work always uses the local copy of the entities first. So in the second TestEntities call, it will find that it already has the returned entities mapped, and use those. To force the unit of work to reload the entities from the database, call unitOfWork.SaveChanges(true). The "true" flag tells the unit of work to invalidate / discard all
existing entities, and force them to be reloaded from the database.
Note that any pending changes will be saved. Thus: var data = unitOfWork.TestEntities.ToList(); // maps the returned entities into the UOW |
|
|
unitOfWork.SaveChanges(true) works as expected, but i don't need save pending changes. I want pending changes to be reloaded from the database. How can i do it? Is BeginEdit and EndEdit methods the only way? related thread: How to clear all pending changes in entity and reload it from database ? |
|
|
I use stored procedures to save chages in the database.
|
|
|
I won't create new UnitOfWork each time when want reload entities from the database, because of, as i understand, new UnitOfWork is a new connection to the database and i can perfomance issue. (Or UnitOfWork creation method uses connection pool ?) |
|
|
At the moment, the only ways reload entity data from the database are (a) to do a SaveChanges(true), and (b) to create a new unit of work and load the entities into that. BeginEdit and CancelEdit/EndEdit will not help because CancelEdit just reverts to the state when BeginEdit was called; it does not reload from the database. |
|
|
related thread: Database connections pool for UnitOfWork |
|