寻找合并的INSERT / UPDATE / DELETE语句,MERGE正是我所需要的,但我似乎无法找到LINQ / SQL是否支持它(来自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;
答案 0 :(得分:2)
LINQ to SQL
的当前版本未生成MERGE
语句。您必须在代码中创建自定义Upsert
方法才能执行Upsert
。