Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to perform delete rows on some condition with EF?

in ADO.NET I can use delete statement

to delete some rows from an SQL table.

what is the equivalent in Entity Framework?

How can I achieve that same result?

updateing with null objects isn't the same.

like image 468
Elad Benda Avatar asked Sep 05 '25 03:09

Elad Benda


1 Answers

Replies telling you, that you need to first fetch objects (strictly speaking keys are enough, but then you need to do some work manually) into memory and mark them for deletion and finally call SaveChanges. Though that's the "normal" approach, there's bunch of extensions, helpers, ... that allow you to do i.e. batch deletes, batch updates and other helpful stuff.

You can check EntityFramework.Extended (also on GitHub) or Entity Framework Extensions (sources there as well).

like image 143
cincura.net Avatar answered Sep 07 '25 21:09

cincura.net