Page 1 of 1

Failed SubmitChanges()

Posted: Wed 30 Mar 2011 21:30
by fmarakasov
Hello!
Here is a scenario, where SubmitChanges() fails with DB exception.
Use three tables (in my case i used SQL Server 2008):
R1(Users) = {ID(PK, int, identity), Name(varchar(100), not null)}
R2(Orders) = {ID(PK, int, identity), UserID(FK, int), StatusID(FK, int), SomeData}
R3(Status) = {ID(PK, int, identity), Name(varchar(100), not null}


The following code will lead to exception on SubmitChanges() with message "The INSERT statement conflicted with the FOREIGN KEY constraint \"FK_Orders_Users\". The conflict occurred in database \"TEST\", table \"dbo.Users\", column 'ID'.\r\nThe statement has been terminated."

Code: Select all

using (TestDataContext ctx = new TestDataContext())
            {
                IBindingList bl = ctx.Users.First().Orders.GetNewBindingList();
                Order order = new Order();
                order.Status = ctx.Statuses.First();
                bl.Add(order);
                bl.Remove(order);                
                ctx.SubmitChanges(); 
            }
But the next code will go fine:

Code: Select all

using (TestDataContext ctx = new TestDataContext())
            {
                IBindingList bl = ctx.Users.First().Orders.GetNewBindingList();
                Order order = new Order();
                // order.Status = ctx.Statuses.First();
                bl.Add(order);
                bl.Remove(order);                
                ctx.SubmitChanges(); 
The next code works, but object remains in BindingList:

Code: Select all

using (TestDataContext ctx = new TestDataContext())
            {
                IBindingList bl = ctx.Users.First().Orders.GetNewBindingList();
                Order order = new Order();
                order.Status = ctx.Statuses.First();
                bl.Add(order);
                order.Status = null;
                ctx.SubmitChanges(); 
Thanks

Posted: Thu 31 Mar 2011 17:03
by StanislavK
Thank you for the report, we've reproduced the problem. We will analyze it and inform you about the results.

Posted: Fri 07 Oct 2011 09:43
by StanislavK
We have fixed the issue, the fix is available in the latest 3.0.5 build of LinqConnect. The new build can be downloaded from
http://www.devart.com/linqconnect/download.html
(the trial only) or from Registered Users' Area (for users with active subscription only).

For more information about the fixes and improvements available in LinqConnect 3.0.5, please refer to
http://www.devart.com/forums/viewtopic.php?t=22168