New Posts New Posts RSS Feed: Deleting a number of items from a large list
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Deleting a number of items from a large list

 Post Reply Post Reply
Author
Randar View Drop Down
Newbie
Newbie
Avatar

Joined: 13-May-2011
Location: Toronto
Posts: 23
Post Options Post Options   Quote Randar Quote  Post ReplyReply Direct Link To This Post Topic: Deleting a number of items from a large list
    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.
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post 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 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.
Back to Top
ting View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 27-Mar-2009
Location: San Francisco
Posts: 427
Post Options Post Options   Quote ting Quote  Post ReplyReply Direct Link To This Post 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:

Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down