Failed SubmitChanges()

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
fmarakasov
Posts: 5
Joined: Fri 21 Jan 2011 16:12
Location: RU

Failed SubmitChanges()

Post by fmarakasov » Wed 30 Mar 2011 21:30

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

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

Post by StanislavK » Thu 31 Mar 2011 17:03

Thank you for the report, we've reproduced the problem. We will analyze it and inform you about the results.

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

Post by StanislavK » Fri 07 Oct 2011 09:43

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

Post Reply