Print Page | Close Window

Deleting a number of items from a large list

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=2683
Printed Date: 30-Jul-2026 at 2:24am


Topic: Deleting a number of items from a large list
Posted By: Randar
Subject: Deleting a number of items from a large list
Date Posted: 17-May-2011 at 11:57am
What is the best practice when you want to delete a small number of items from a large list?  e.g. Say you have 2000 records in a table and you want to delete 4 of those.  Seems like a bad idea to load the entire list, mark the ones you want to delete (as per http://drc.ideablade.com/xwiki/bin/view/Documentation/entity-deletion) and then save the EntityManager.

I assume a better model, is load those specific items and then delete them.  But that is still quite a few network calls.  I guess what I'm really looking for is the equivalent of:

DELETE FROM Table1 where TableId in (1,5,6,9)

p.s. I know somebody might make the argument that you would want to check that it's there before you delete it, but I don't care.  If it's gone for some other reason, it's gone and I'm happy.



Replies:
Posted By: sbelini
Date Posted: 17-May-2011 at 1:12pm
Hi Randar,
 
If you simply want to delete the entities without even loading them in the client. I suggest you create a store procedure, add it to the model, and add a “Function Import” to represent the stored proc in the model.
 
The Stored Procedure Query walkthrough in the http://drc.ideablade.com/xwiki/bin/view/Documentation/code-sample-stored-procedure-queries-silverlight - DevForce Resource Center provides the steps to follow (note that when adding the Function Import you will be returning nothing instead)
 
I hope it helps.
 
Silvio.


Posted By: ting
Date Posted: 17-May-2011 at 3:43pm
Loading those specific entities and then deleting them is two network calls, which shouldn't be bad for most scenarios.

If you don't want to bring them down to the client, you can also invoke a server-side method (and use the server-side EntityManager) to delete them:
http://drc.ideablade.com/xwiki/bin/view/Documentation/rsmc-query - http://drc.ideablade.com/xwiki/bin/view/Documentation/rsmc-query




Print Page | Close Window