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! I have the following problem. I have an entity, for example, Entity1. This entity is attached to some UnitOfWork. I remove the entity from this UnitOfWork and during uow.SaveChanges() I get some exception. Therefore, no changes happen to database, but the state of the Entity1 changes, so I can't just catch the exception and continue to use this entity. And I don't want to reload it from database. I thought about three ways to solve this problem. Firstly, I tried to make a clone of this entity before removing it from UnitOfWork, but I found out that Id and EntityState are readonly. Secondly, I thought about DTO, but as I understood in this case the entity will be reloaded from database. Thirdly, I tried to use binary serialization to keep the entity, but unfortunately the process of serialization and deserialization is slow. So, can you give me advice how to solve this problem? Thank you!
|
|
|
Hmm, the state of Entity1 shouldn't be changing if the save fails -- it should remain in the Deleted state. You can detach an entity from a UOW by calling IUnitOfWork.Detach(entity). |
|