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
|
Hello. In my winforms application I am experimenting with differents forms of managing the units of work and I need to know how these behaves in certain cases. 1) Disposing UOW Can I access an entity attached to a disposed UOW? I saw an exception when accessing to lazy loaded related entity, this is correct, but can I use a entity attached to a disposed UOW? When a UOW is really disposed?, when all attached entities are not in use? 2) I can attach a entity loaded in a UOW to another UOW, I suppose that this entity is now only attached to this UOW. 3) What does LS when loading entities already in memory and referenced by the application? I don't know if LS ignore the new loaded entities or what else?
Thank you. |
|
|
"Can I access an entity attached to a disposed UOW?" Yes, but with some limitations. Specifically, as you have noticed you cannot traverse any lazy associations (because these would result in a database load). Basically you cannot do anything that might trigger further database interaction. "When is a UOW really disposed?" When you call Dispose() on it (explicitly, or implicitly at the end of a using block). "I can attach a entity loaded in a UOW to another UOW, I suppose that this entity is now only attached to this UOW." That is correct. The entity is no longer registered with the old unit of work. For example, if you do an oldUnitOfWork.SaveChanges(), this will not save the entity that you attached to the new unit of work. "What does LS when loading entities already in memory and referenced by the application?" If a database query results in an entity that is already registered in the UOW (i.e. the identity map contains an entity of the same type and ID), then that existing entity is used (i.e. the query returns a reference to the existing entity rather than materialising a new one). Note that this refers only to entities that already exist in the UOW at hand. If there is another UOW in memory for some reason, entities in that UOW are not considered: each UOW has a separate identity map. |
|