I have a method to delete all my tables.
I’d like to know if I can:
(1) Iterate over the meta data in the model to accomplish the same thing?
(2) Reset the Identity Insert counts along the way?
Note: I don’t want to delete the entire database, just all the tables.
Here’s the code I want to convert to a generic loop:
public void Delete() {
using (var db = this.DirectAgentsEntities)
{
db.StartingBalances.DeleteObjects(db.StartingBalances);
...
db.RecordSourceTypes.DeleteObjects(db.RecordSourceTypes);
db.SaveChanges();
}
}
static class Extensions {
static public void DeleteObjects<TEntity>(this ObjectSet<TEntity> set, IEnumerable<TEntity> data) where TEntity : class {
foreach (var entity in data)
set.DeleteObject(entity);
}
}
It may be simpler to:
The edmx file is just xml, so you could loop through it, then for each table you find: