Print Page | Close Window

Any fast way to clear a table?

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2009
Forum Discription: For .NET 3.5
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=1147
Printed Date: 02-May-2025 at 2:55am


Topic: Any fast way to clear a table?
Posted By: ken.nelson
Subject: Any fast way to clear a table?
Date 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



Replies:
Posted By: kimj
Date 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(..);
 
 

 



Print Page | Close Window