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
|
It looks like LightSpeed doesn't delete objects from its entity map in UOW.Remove/UOW.SaveChanges and returns them when asked for in FindById. I attach an example:
This example was tested on nightly build from Dec 15th. Aren't objects permanently deleted after executing UOW.Remove/UOW.SaveChanges? |
|
|
Entities remain in the identity map after SaveChanges unless you pass true for the reset option: _unitOfWork.SaveChanges(true); This is because the unit of work is a "work in progress" until it is disposed or reset. |
|
|
Well, setting reset=true is too heavy for me - it forces all entities to be reloaded. I decided to use long-lived UOW (discussed in one of my previous threads) and reloading all entities would destroy almost all my architecture concepts. Wouldn't it be possible to force cleaning of entity map? I could call it separately (after SaveChanges()) and I agree it would require some time to proceed. I appreciate your fast reactions to the users' needs and I think I have never met any company which reacts so fast and reliable as Mindscape. :-) |
|
|
We don't have an option to clear the identity map, but you can customise the behaviour using an extension method: public static T FindUndeletedById<T>(this IUnitOfWork uow, object id) |
|
|
Unfortunately it doesn't work :-( After SaveChanges(), the deleted entity has EntityState==EntityState.Default, and the above method returns deleted entities :-( Maybe I could get access to the entity map in the overriden UnitOfWork class and remove the deleted entities myself? |
|
|
Oops, you're right. Sorry about that. The overridden unit of work class does not provide direct access to the identity map, but you can use the Detach method to remove entities from the entity map (and hence from the UOW). You could even override SaveChanges(bool) to do this automatically -- something along the lines of: public override void SaveChanges(bool reset) { (I know you are calling SaveChanges() but this delegates internally to SaveChanges(false) so the override would still kick in.) Or perhaps more safely add your own SaveChangesAndClearDeleted() method. |
|
|
It works perfect! Thank you. |
|