Delete if Exists

Posts   
 
    
cmprogrock
User
Posts: 40
Joined: 16-Nov-2008
# Posted on: 02-Jul-2009 04:20:56   

Hi,

I'm Deleting an entity by taking an ID (int). Example: (Partial) PageBlogEntity pagB = new PageBlogEntity(PageID); rtn = adapter.DeleteEntity(pagB);

It works...but Error if ID has already been Deleted.

ANY GOOD WAY TO TEST IF EXISTS?

Thanks, cm

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 02-Jul-2009 04:41:21   

You have these options, as I see:

A. Try to fetch a copy of the entity, and see if it return something (the IsNew property will be true if it has been deleted). Then if it exists, delete it.

B. Perform a DeleteMulti specifying the correct filter for that ID. That wont fire an exception and will let you know how many records had been affected (1 or 0).

C. Do what you are doing. It's not that bad. You don't know if someone else deleted it, so you should trap any exception and do something with that (notify to the user, etc.).

David Elizondo | LLBLGen Support Team