I have my favorite project written in php. One of my tasks is to load a bunch of csv files and write them to a MySQL table, which have both an auto-generated primary key and a multi-purpose unique key. I have no control and verification methods - this is an already processed file, so a unique key was at hand. I insert data into a table with help INSERT IGNORE
that silently fails when I try to insert data that already exists, and everything works fine, as it should.
Now I'm trying to make a similar project in C # 4 using LINQ To Entities, but when I try to call a method ObjectContext.SaveChanges()
for objects from files that are already in the table, it UpdateException
is created with SqlClient.SqlException
an internal exception. One solution was to add Ignore Duplicate Keys = Yes
to the index, and it kind of works, but
- This is a change on the server instead of the client
- OptimisticConcurrencyException thrown when updating using an existing index
Is there a simple and elegant way to perform these inserts with L2E that are not related to database changes?
source
share