Error on SubmitChanges

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
motaboyrs
Posts: 3
Joined: Mon 31 Oct 2011 17:38

Error on SubmitChanges

Post by motaboyrs » Mon 31 Oct 2011 17:50

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.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Tue 01 Nov 2011 12:24

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.

motaboyrs
Posts: 3
Joined: Mon 31 Oct 2011 17:38

Post by motaboyrs » Tue 01 Nov 2011 15:07

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.

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Wed 02 Nov 2011 17:04

Thank you for your assistance, we have reproduced this issue. We will analyze it and inform you when it is fixed.

Lucas Phillip
Posts: 10
Joined: Wed 29 Jun 2011 14:37

Post by Lucas Phillip » Fri 11 Nov 2011 13:00

I dont know if it is helpful or not, but I belive I'm having the same issue using Postgre 9.1

StanislavK
Devart Team
Posts: 1710
Joined: Thu 03 Dec 2009 10:48

Post by StanislavK » Tue 15 Nov 2011 17:46

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.

Post Reply