Obtaining MarkedForDeletion Entities

Posts   
 
    
miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 11-Jul-2011 10:56:03   

Hi,

I have the following situation:

EntityCollection of some object is fetched from a DB. Some of child objects (prefetch paths) are handled by the UnitOfWork and during that work they're removed (unitOfWork.AddForDelete(entity)wink . After that the UOW is commited. After that operation the EntityCollection is handled by other module and I need to know which prefetch path's object were removed. If I won't do that I'm receiving the exception, that entity has been removed from a db.

I've found out that each entity has protected internal bool MarkedForDeletion { get; set; } Field but its internal disappointed . How can I determine which objects are marked for deletion? I need to filter the EntityCollection, so I can also use method build in that object (if any exists).

Regards, MiloszeS

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Jul-2011 11:25:57   

Can you do it th eother way around, i.e. remove entities from the collection and the use the Tracking Removes feature to delete them afterwards, from the database.

miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 11-Jul-2011 11:44:03   

The problem is that I don;t know what other modules are doing. Its provided by other company. The modules are handling some ContentEntity and made specific things on it or accourding to data stored in that object. Those modules shares a UOW and changed the objects via UOW. After that the UOW is committed.

I'll try to contact other code providers to change it as you said, but I cannot be 100% sure that some other dev in the future modify the code or write other module and forget about it. The problem is that my module is at the end of the execution list and I want to safe my code against such problems in the future.

Its a very big problem for me because a problem occured in the production environment in my module. I know that a problem is not 100% my fault, but I need to prove it in the future and investigate which module change that. It would be much better if I could just filter such entities and wirte eventually a warn log, that someone has handled that inproperly, but my module will handle that data.

Its very rare situation but it happened for 1 user and he cannot work until I fix that.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Jul-2011 12:00:41   

In that case, you'd better just refetch everything.

This way you rely on the database to be the shared storage between all components, and you'd just fetch the graph just before ou consume it, and don't keep it in memory for too long.

miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 11-Jul-2011 12:21:17   

Ok, it should work for now. But what about the future. Refetching the data each time (for each module) will be inefficient. Moreover whould the UOW will commit correctly when I Refetch the data in one of mines modules?

You're providing flags IsNew, IsDirty. Why MarkForDeletion flag should be internal (the setter is obvious, but getter...)?

Maybe some Getter IsDeleted or similar could be provided in next version ?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 11-Jul-2011 14:25:05   

Please check myEntity.Fields.State

miloszes
User
Posts: 222
Joined: 03-Apr-2007
# Posted on: 11-Jul-2011 14:37:52   

Great - that was what I was looking for simple_smile . It resolved my problem without additional workload.

Thanks for a great support. MiloszeS