Attach an entity that is not new, perhaps having been loaded from another DataContext. LINQ to SQL -
- by soldieraman
Alright
How I got this error
I got one application sitting on a server
2 users accessing this application - doing some bulk data processing . eg. entering values and then the application is working with another system to extract values for them and then saving.
I can't recreate the error
The error logs show:
The error happend at the same time in both the application
Both happend on a Attach/Submit (but two different functions)
There is no way they are using the same DataContext object as I save the DataContext in the HttpContext.Items
My hunch / guess is:
One datacontext was not refreshed i.e. the an object was created for the same item twice as it was new in both the forms. eg. Customer Number - a customer was created (as one couldn't be found) by one datacontext - the other one couldn't find it either (i am using compiled queries to find it in the datacontext) so it created another object and on attaching failed.
The HttpContext.Items lost its value somehow (i am using a virtual pc as server - maybe something went wrong there)
I am going more of the second as I can't recreate the error - but it just might be a timing (for attach/save) thing - also the error makes me think of the 2nd too.