开发者

How to delete multiple records in entity framework without looping using LINQ?

开发者 https://www.devze.com 2022-12-31 05:15 出处:网络
I want to deletemultiple records in entity framework without using a for loop or any other loop using LINQ. Something that we can do it in SQL is there any way to delete multiple records in enti开发者

I want to delete multiple records in entity framework without using a for loop or any other loop using LINQ. Something that we can do it in SQL is there any way to delete multiple records in enti开发者_如何转开发ty framework?


What you want to do is not supported using Entity Framework. Entity Framework needs to load an object into memory, before you can delete it. This way it can do its optimistic concurrency checks.

If you really need this, you will have to do this with pure SQL or better, use a stored procedure. You can call your stored procedure with Entity Framework.


using (var context = new DatabaseEntities())
{
    context.ExecuteStoreCommand("DELETE FROM YOURTABLE WHERE CustomerID = {0}", customerId);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消