Consider the following code sample:
foreach(EntityData data in Data)
{
Entity entity = CreateEntity(data);
dataContext.Entities.InsertOnSubmit(entity);
try
{
dataContext.SubmitChanges();
}
catch(SPDuplicateValuesFoundException e)
{
// Log that given entity already exists
}
}
// Update other entity that contains, let's say the total of inserted entities without errors.
The issue here is, that after the SPDuplicateValuesFoundException occur for the first time in the dataContext.SubmitChanges() call. It always occurs on all the subsequent dataContext.SubmitChanges() calls. I guess LINQ to SharePoint tries to save that same entity again. It is not clear for me how to force LINQ to SharePoint not to do this.
What would you recommend? Is there any way to force LINQ to SharePoint not to save the entity after the exception occur? And also do you guys have such behavior in your environment? Because I may be using LINQ to SharePoint not in the right way.
Thanks.