views:

68

answers:

3

Hi currently when I want to clear my tables I use brute force:

        inventario_dboEntities inv = new inventario_dboEntities();            

        foreach (var item in inv.espiromex_dampers)
        {
            inv.DeleteObject(item);
        }
        foreach (var item in inv.espiromex_detalles)
        {
            inv.DeleteObject(item);
        }
        foreach (var item in inv.espiromex_docs)
        {
            inv.DeleteObject(item);
        }

I am sure there must be a better more elegant way to do this... how you guys do this kind of task?

+2  A: 

We do it by restoring a "baseline" DB from backup.

Craig Stuntz
+1  A: 

Another option you have in Entity Framework is to use ExecuteStorecommand do this db.ExecuteStoreCommand(@"delete table1;delete table2;delete table3;");

zeeshanhirani
+1  A: 

I think the best way and best practice is to truncate them in your query browser (since you are using MySQL) or as @TheCloudlessSky said using a stored procedure.

Also (but I am not sure) you could use Reflection and some fancy stuff.

Back UP