开发者

How to accomplish, in LINQ, what would be InsertAllOnSubmitAndIgnoreDuplicates()?

开发者 https://www.devze.com 2023-03-29 13:01 出处:网络
I have a batch of records that I am adding to a table using LINQ, through a very simple: context.MyTable.InsertAll(myNewRecords);

I have a batch of records that I am adding to a table using LINQ, through a very simple:

context.MyTable.InsertAll(myNewRecords);
context.SubmitChanges();

Works great, unless some of those records are already in the table (primary key violation). If this were MySQL, I'd use "ON DUPLICATE UPDATE". But it's S开发者_如何学编程QLEXPRESS 2008 and its LINQ, so I'm stuck.

Is there any performant way to do an InsertAll and have it update when it matches a row? I'd even live with "ON DUPLICATE IGNORE" at this point. Since it's the primary key, I do not think I can use the MSSQL 'ignore duplicate key' attribute on the primary key (it's greyed out in SQL Management Studio when I bring up the key properties).

0

精彩评论

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