New Posts New Posts RSS Feed: Any fast way to clear a table?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Any fast way to clear a table?

 Post Reply Post Reply
Author
ken.nelson View Drop Down
Groupie
Groupie


Joined: 03-Mar-2009
Location: Ann Arbor, MI
Posts: 54
Post Options Post Options   Quote ken.nelson Quote  Post ReplyReply Direct Link To This Post Topic: Any fast way to clear a table?
    Posted: 18-Mar-2009 at 11:36am
Hi,
 
I'm basically looking for a way to truncate or delete all records from a table.  The slow and painful way is to simply iterate over all entities, delete() them, then save changes, but I'm wondering if there's a better way?
 
Thanks,
Ken
Back to Top
kimj View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 1391
Post Options Post Options   Quote kimj Quote  Post ReplyReply Direct Link To This Post Posted: 19-Mar-2009 at 6:50pm
Unfortunately, no.  Using DevForce, you need to first load all those entities into cache, and then either Delete() them or ensure that a cascaded delete affects them. 
 
If you don't need to treat the data as entities and only need a means of performing bulk operations on the database, you can use the AdoHelper in IdeaBlade.Rdb to drop into ADO.NET.  It's a bit of a convoluted path to get there, but it's something like this:
 
      IDataSourceKey key = myEntityManager.DataSourceResolver.GetDataSourceKey("Default");
 
      // cast or use appropriate EdmKey constructor
      IdeaBlade.EntityModel.Edm.v4.EdmKey edmKey = dataSourceKey as IdeaBlade.EntityModel.Edm.v4.EdmKey;
    
      RdbKey rdbKey = edmKey.RdbKey as RdbKey;
      AdoHelper helper = rdbKey.AdoHelper;
 
      // Can now create DB connection and commands directly.
      var command = helper.CreateDbCommand(..);
 
 

 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down