How should I remove all elements in a DbSet?
问题 What's the best way to remove all elements in a System.Data.Entity.DbSet, with Entity Framework 4.3? 回答1: dbContext.Database.ExecuteSqlCommand("delete from MyTable"); (No kidding.) The problem is that EF doesn't support any batch commands and the only way to delete all entities in a set using no direct DML would be: foreach (var entity in dbContext.MyEntities) dbContext.MyEntities.Remove(entity); dbContext.SaveChanges(); Or maybe a litte bit cheaper to avoid loading full entities: foreach