Deleting multiple records with Entity Framework using a single LINQ query

后端 未结 2 2061
北恋
北恋 2021-02-20 10:16

I\'m trying to perform a DELETE using LINQ that will generate a single query.

Here\'s how I\'m doing it:

// Northw         


        
2条回答
  •  悲哀的现实
    2021-02-20 11:04

    1. Install Entity Framework Extended Library (PM> Install-Package EntityFramework.Extended)

    2. Import EntityFramework.Extensions in your code

    3. Delete records specified by inner query

      context.Orders.Where(o=>o.User_ID == 1).Delete();
      

    Deletes all records inside Orders with userID = 1

提交回复
热议问题