Can Linq in SQL / Linq for Entities generate a MERGE statement?

Looking for the combined INSERT / UPDATE / DELETE statement, MERGE is exactly what I need, but I can not find if LINQ / SQL supports it (from http://www.sqlbook.com/SQL-Server/SQL-MERGE -35.aspx )

-- Merge order items into OrderItems table MERGE INTO OrderItem As oi USING @UpdatedItems ui ON (oi.OrderID = ui.OrderID AND oi.ProductID = ui.ProductID) WHEN MATCHED THEN UPDATE SET Quantity = ui.Quantity, UnitCost = ui.UnitCost WHEN NOT MATCHED THEN INSERT (OrderID, ProductID, Quantity, UnitCost) VALUES (@OrderID, ui.ProductID, ui.Quantity, ui.UnitCost) WHEN SOURCE NOT MATCHED THEN DELETE; 
+4
source share
1 answer

The current version of LINQ to SQL does not generate a MERGE . You must create your own Upsert method in your code to make Upsert .

+2
source

Source: https://habr.com/ru/post/1314242/


All Articles