ahcruzado (2) [Avatar] Offline
Hello people:

First of all forgiveness for my English.
I am working with Linq to SQL, Visual Studio 2008 Trial Version 90 Days and SQL Server 2000.
When you delete a record and then go back to Insert (ie, insert a record
with the same primary key)
and I run SubmitChange it generates an key duplicate exception.
I am reviewing the SQL commands generated by linq, and I see that attempts
to run
first insert command, and then delete command.
I imagine that this is the problem because I expected the first run delete
and then Insert.
Any thoughts on this?
jwooley (123) [Avatar] Offline
Re: Linq To Sql Delete
If you want to ensure that the commands are run in the order you specify, you may need to call SubmitChanges more frequently. LINQ to SQL uses a Unit of Work pattern rather than a work queue, thus it retains all of the inserts, updates and deletes in separate collections in the context. When the SubmitChanges is called, it evaluates them to cascade delete child objects if necessary, but does not check for the situation you are running into.

I suggest you direct your question to the official LINQ forum at http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=123&SiteID=1 if you need additional information regarding this behavior as it is monitored by the actual product teams.
ahcruzado (2) [Avatar] Offline
Re: Linq To Sql Delete
Thank you.

Yesterday I answered from ADO.NET Team and told me that it should work. In addition, they commented that a removal / insertion should be recognized by linq and generate a command Update.
As this is not what I see in SQL Analyzer. I send the source Code.
I am waiting their respond.
Thank you and greetings