Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linq to SQL Data context doesnt commit if multiple inserts are called on table with auto increment

I am having an issue when trying to submit two inserts at once. The table has a auto increment primary key. The comment objects set up dont have there ID value set so that the database can assign this.

My code works for single inserts if i submit straight away but if i try and do multiple InsertOnSubmit commands then it seems to do nothign, and returns no errors or exceptions even though my code is within a try and catch block. Has anyone else had this problem or do you know which direction i should be looking?

Example 1 (This doesn't commit to the database)

//myComment is initialised with data
dc.tblDailyComments.InsertOnSubmit(myComment);


//myComment2 is initialised with different data
dc.tblDailyComments.InsertOnSubmit(myComment2); 


//when this is called it does not commit to the database   
dc.SubmitChanges();

Example 2 (This works fine)

//myComment is initialised with data
dc.tblDailyComments.InsertOnSubmit(myComment);

//commits to the database   
dc.SubmitChanges();

//myComment2 is initialised with different data
dc.tblDailyComments.InsertOnSubmit(myComment2); 


//commits to the database   
dc.SubmitChanges();
like image 841
Andrew Avatar asked Jul 04 '26 07:07

Andrew


1 Answers

Reported as issue by Michael Barth to Microsoft

https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=483711

like image 187
Andrew Avatar answered Jul 06 '26 21:07

Andrew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!