Delete last N records, Entity Framework

c# entity-framework entity-framework-6

Accepted Answer

Your approach is acceptable. TheRemoveRange() Multiple items can be removed from the database using a procedure. Additionally, the approach you're using to acquire the remaining n goods is suitable. HoweverTakeLast() will only return entries that were most recently added to the database, in that order.

1
5/14/2016 2:40:20 PM

Popular Answer

What about

var lastN = MyDbContext.MyDbSet
                       .OrderByDescending(g => g.Id)
                       .Take(N);

MyDbContext.MyDbSet.RemoveRange(lastN);


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow