Entity Framework. Delete all rows in table

前端 未结 21 2038
一生所求
一生所求 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:58

    In my code I didn't really have nice access to the Database object, so you can do it on the DbSet where you also is allowed to use any kind of sql. It will sort of end out like this:

    var p = await _db.Persons.FromSql("truncate table Persons;select top 0 * from Persons").ToListAsync();
    

提交回复
热议问题