Hey,
I'm using Telerik Data Access and have a use case where I need to bulk insert thousands of rows (as part of XML parsing logic) into a SQL server database table.
The records I'm inserting do not have a natural primary key, so I created a surrogate (simple autoincrement int). I do however have declared a unique key index on the table (spanning about 6 columns) to determine as much as possible the uniqueness of the record.
Now I want to do the following with Telerik Data Access:
1) Insert thousands of records as fast as possible
2) Whenever a DuplicateKeyException is detected, ignore that entity and move on to the next one.
What I currently have is a foreach looping over all entities to save, and then call a "Save" method (all using the same context).
Inside the save method I "try" to add the entity to the context, call savechanges and then "catch" for DuplicateKeyException, but I'm not sure what to write in the catch to "ignore" the exception and remove the entity from the context. It seems that if I just catch the exception, all subsequent calls to savechanges rethrow the same exception as the entity is kept into the context.
Any advise on this ?
Any other approaches you would recommend ?
thanks
Mathieu