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
|
Hi, I am trying to use code like that below to create an entity and update the values of it in the same UOW, so that it can be persisted at the end of the UOW. However with this code the entity will not be found in the Update method. It will be found if I call uow.SaveChanges before updating, however that is not quite what I intended. What would be the flow for this use case? Thanks
in the repository:
|
|
|
In the Update method, use |
|
|
Ah, I see. Thanks! Is there a way to make it work like that for a unique key column as Map key as well? |
|
|
No, unfortunately in this case you need to use write a little helper to check both the database and the local identity map:
In this example I check the database first; depending on the size of your UOW and the likelihood of the entity being already in memory it may be more efficient to check the identity map first (or it may not make much difference either way!). You can obviously make this more reusable using generics and lambdas if you have a lot of these 'get by unique key' lookups. |
|
|
Ok, thanks alot! |
|