I have two tables.
Table1:
Id Int Not Null, Auto Increment, Primary Key,
Name Varchar(100)
Table2:
Table1Id Int Not Null Primary Key, Foreign Key to Table1,
Name Varchar(100)
table1 = new Table1();
table1.Name = "Test1";
table2 = new Table2();
table2.Name = "Test2";
table2.Table1 = table1;
On SubmitChanges it throws the error "The INSERT statement conflicted with the FOREIGN KEY constraint...", but if I add another table, let's say, Table3 and make the Table2 refrences the Table3, it works.
What am I doing wrong?
If additional information on the code is necessary, just ask.
Thanks.
Error on SubmitChanges
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
Could you please specify the following:
- the version of LinqConnect you are using;
- the DBMS (e.g., SQL Server or MySQL) you are working with;
- the exact way you are saving the new entities (e.g., do you call the InsertOnSubmit method for the 'master' or 'detail' entity?);
- the SQL commands generated to save the entities (to check them, you can, e.g., enable logging for your DataContext).
If possible, please send us a small sample with which the issue can be reproduced. At the moment, we couldn't reproduce it in our environment.
- the version of LinqConnect you are using;
- the DBMS (e.g., SQL Server or MySQL) you are working with;
- the exact way you are saving the new entities (e.g., do you call the InsertOnSubmit method for the 'master' or 'detail' entity?);
- the SQL commands generated to save the entities (to check them, you can, e.g., enable logging for your DataContext).
If possible, please send us a small sample with which the issue can be reproduced. At the moment, we couldn't reproduce it in our environment.
Sorry, forgot that.
-LinqConnect 3.0.10 Pro
-SQL Server 2008
-I call the InsertOnSubmit for the master entity(Table1)
-If I add the other FK, for Table3, it will be executed in the proper order:
Insert into Table1 and then Insert into Table2.
Without the FK for Table3, it tries to insert first the Table2, but as Table1 don't have the PK value yet, the
linqConnect throws the error.
I've sent an example in VS2008 C# .Net 3.5.
-LinqConnect 3.0.10 Pro
-SQL Server 2008
-I call the InsertOnSubmit for the master entity(Table1)
-If I add the other FK, for Table3, it will be executed in the proper order:
Insert into Table1 and then Insert into Table2.
Without the FK for Table3, it tries to insert first the Table2, but as Table1 don't have the PK value yet, the
linqConnect throws the error.
I've sent an example in VS2008 C# .Net 3.5.
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
-
- Posts: 10
- Joined: Wed 29 Jun 2011 14:37
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48