Delete all entities in Entity Framework

后端 未结 8 1667
天命终不由人
天命终不由人 2020-12-13 17:10

I want to delete content of all tables (all entities) using Entity Framework 4+. How can this be done?

相关标签:
8条回答
  • 2020-12-13 17:44

    This works for me... EF v3.1.5

    context.ModelName.RemoveRange(context.ModelName.ToList());
    context.SaveChanges();
    
    0 讨论(0)
  • 2020-12-13 17:46

    (In .NetCore) You can use RemoveRange on the table with the table itself as Parameter.

    Tablename.RemoveRange(Tablename);
    
    0 讨论(0)
提交回复
热议问题