How to accomplish, in LINQ, what would be InsertAllOnSubmitAndIgnoreDuplicates()?
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).
精彩评论