Dealing with a Deleted Entity

Posts   
 
    
Answer
User
Posts: 363
Joined: 28-Jun-2004
# Posted on: 15-Dec-2006 18:57:04   

Hi all,

I am just wondering how everyone here deals with the following scenario..

You have two people working at the same time, person A loads some data then person B loads the same data. Person A deletes an entity. Person B then Saves that same entity...Person B will now get an ORMConcurrency exception..

How do you generally handle this?? On some Forms i am prefetching and saving entities 3 levels deep...and im not sure how i should handle/deal with this situation..

MY setup.. Sql 2005 LLBLGen Pro 2.0 IIS Applciation Server running remoting Smart Client

KristianP
User
Posts: 32
Joined: 23-Feb-2005
# Posted on: 15-Dec-2006 19:04:28   

We decided for most of tables, we do not allow deletes, but rather have an 'Active' column. This adds one more condition to your bucket on fetches, but all in all its not to bad. So to answer your question, you could pass in an update restriction to your save method and make sure the active column is set to true. So you won't get any exceptions, but the save method will return false.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 15-Dec-2006 20:32:36   

I once wrote an article about this: http://weblogs.asp.net/fbouma/archive/2003/05/24/7499.aspx

About not doing deletes and use an active column: Don't do this. This isn't going to work in the long run because the amount of data in the db will increase and the size of the working set you work with will stay the same, so the application will become slower and slower.

Deleted data in that kind of situation is actually archived data. Either delete what you want to delete, or use a set of triggers which copy the row over to an archive schema before delete.

Frans Bouma | Lead developer LLBLGen Pro
Answer
User
Posts: 363
Joined: 28-Jun-2004
# Posted on: 16-Dec-2006 19:22:09   

Great article Otis,

I read that once before ( i read all your articles/blogs) but i totally forgot about it.

So you suggest a more pessimistic approach which was something i was against prior, but it does actually make sense.

simple_smile