Bug #61370 Multiple insert in the same transaction, using linq to entities
Submitted: 1 Jun 2011 8:49 Modified: 3 Jul 2011 15:39
Reporter: aaa bbb Email Updates:
Status: No Feedback Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:6.3.6 OS:Windows
Assigned to: Assigned Account CPU Architecture:Any
Tags: entity framework, linq to entities, multiple insert, savechanges

[1 Jun 2011 8:49] aaa bbb
Description:
If I try and insert a new parent and child (2 rows that are connected by a foreign key) it will throw and exception saying that "an error occurred while updating the entries. See the inner exception for details."

The single transaction that is created by the savechanges() method is not able to insert the 2 rows.

It works as it should in microsoft sql server.

How to repeat:
Have 2 tables (named: parent, child) connected by a foreign key. 
Add a model of the database using "ado.net entity data model" in visual studio.
Insert a row in each table using linq to entites like so:

"dbEntities" is the name of the connection string stored in App.config in the visual studio working project; it is generated when adding a new "ado.net entity data model".

using (dbEntities context = new dbEntities())
{
   var newParent  = parent.Createparent(0);
   var newChild = new child();
   // join the new child to the new parent using navigation properties
   newChild.parent = newParent;
   // add the new graph to the context
   context.parent.AddObject(newParent);
   context.SaveChanges();
}

the savechanges() gives the exception.
it the 2 rows are saved separately it works, but each savechanges uses it's own transaction and so each row is saved using a separate transaction and this is bad.

Suggested fix:
I think the connector does not parse correctly the expression tree to see that there is a connection between the parent and child.
[1 Jun 2011 9:43] Bogdan Degtyariov
Thanks for reporting the bug.
Can you provide a test project along with the tables you used? Such bugs can be often related to specific column types etc.
[1 Jun 2011 9:47] Bogdan Degtyariov
Also, the bug severity (S1) is misplaced as it does not represent a complete loss of service, system halt or indefinite hangs without any workarounds.

I must lower it to S2.
[1 Jun 2011 11:46] aaa bbb
While I was trying to make a test file I have noticed that the "unsigned" fields were translated as "signed" in the Entity model.
If I modify all my unsigned fields to be signed in the database and then recreate the model in visual studio, the problem is gone. 
It doesn't really make sense b/c separate savechange() worked (with the same mismatch of signed fields in the entity model and unsigned fields in mysql).

I have also noticed this from MS about "unsigned int" in Linq:
http://msdn.microsoft.com/en-us/library/bb896317.aspx#UnsignedIntsUnsupported

In conclusion, my _unsigned fields_ were translated as _signed fields_.
I don't know if it's a problem with the mysql connector or with linq in general , as mentioned in the above link from msdn.

I will need to test some more with mysql and sql server express.
[3 Jun 2011 15:39] Julio Casal
The specified steps to reproduce do not lead to the specified error. Please include your database creation scripts plus a small sample Visual Studio project where the error appears.
[3 Jul 2011 23:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".