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 need some help... LS make select query to db and get the entity. After a while this entity may be changed in DB by some trigger. How can i update this entity from db? |
|
|
You will want to look at how you are scoping your UnitOfWork. Once an entity is loaded into the UnitOfWork it is cached in the identity map. The identity map is cleared if you call SaveChanges(true) but until that time any requests for an entity which is already in the identity map will be served from memory for consistency. So in your situation you will either want to load the entity into a new UnitOfWork, or make sure if you are using a longer running UnitOfWork that you call SaveChanges(true) on flush to purge the identity map.
|
|
|
i have some like this: extension method:
Calling method:
but identity map still points to old object What am i doing wrong ? |
|
|
There are a couple of things wrong with this. Your update method is importing back the original entity back into the UOW which actually modifies the version in the identity map loaded from the database from the Find call. Also you are not actually updating the original entity. Try this instead:
Called by:
|
|
|
Thanks a lot Jeremy that's work fine. I've one question more... How can i update identity map of uow without return TEntity object? Something like this:
And Call:
|
|
|
You need to be using an Entity If you want to update the original object in place you will need to detach the updated entity, reattach the original entity and then import back in the updated entity to map across the properties which is a rather convoluted process over just fetching an updated copy of the entity. Do you explicitly need to keep the actual original entity around?
|
|