Page 1 of 1

Error on SubmitChanges

Posted: Mon 31 Oct 2011 17:50
by motaboyrs
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.

Posted: Tue 01 Nov 2011 12:24
by StanislavK
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.

Posted: Tue 01 Nov 2011 15:07
by motaboyrs
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.

Posted: Wed 02 Nov 2011 17:04
by StanislavK
Thank you for your assistance, we have reproduced this issue. We will analyze it and inform you when it is fixed.

Posted: Fri 11 Nov 2011 13:00
by Lucas Phillip
I dont know if it is helpful or not, but I belive I'm having the same issue using Postgre 9.1

Posted: Tue 15 Nov 2011 17:46
by StanislavK
Lucas Phillip, thank you for your assistance. This problem is not database-specific (i.e., may occur with different DBMSs). We are working on it and will post here when it is fixed.