Entity Framework. Delete all rows in table

前端 未结 21 2049
一生所求
一生所求 2020-11-28 01:25

How I can quickly remove all rows in table using Entity Framework?

I am currently using:

var rows = from o in dataDb.Table
           select o;
forea         


        
21条回答
  •  南笙
    南笙 (楼主)
    2020-11-28 01:53

    For those that are googling this and ended up here like me, this is how you currently do it in EF5 and EF6:

    context.Database.ExecuteSqlCommand("TRUNCATE TABLE [TableName]");
    

    Assuming context is a System.Data.Entity.DbContext

提交回复
热议问题