CRUD not supported?

Discussion of open issues, suggestions and bugs regarding LinqConnect – Devart's LINQ to SQL compatible ORM
Post Reply
Zero-G.
Posts: 398
Joined: Sat 09 Dec 2006 12:20

CRUD not supported?

Post by Zero-G. » Thu 27 Jan 2011 15:35

Hey

I have a problem with a update/delete szenario.
I have a Master/Detail szenario for customers.
If a customer is in the db twice, then I will give them together, so I do the following:

I give the ID of the detail from on Customer to the other. Then I delete the customer.
I am doing this, by running the following code:

Code: Select all

Dim sKundenID As Int64 = 0
                    For Each cRow In GridEX1.GetCheckedRows
                        sKundenID = CLng(cRow.Cells("KundenID").Value)
                        If sKundenID > 0 Then
                            Dim aKunden = From Query In myDataContext.Auftrags Where _
                                          Query.Kundenid = sKundenID

                            For Each aKunde In aKunden
                                aKunde.Kundenid = myKundenID
                            Next
                            Dim dKunde = (From Query In myDataContext.Kundenstamms Where _
                                          Query.Kundenid = sKundenID).Single
                            myDataContext.Kundenstamms.DeleteOnSubmit(dKunde)
                        End If
                    Next
                    LinqProvider.SaveDataContext(myDataContext)
The problem is, that I get an error: 1 of 2 updates failed
By looking on the output window, I saw, that the DELETE Statement of the customer is fired, before the Update statement of the customersdetail is fired.

Please give me some advise to this.
THX

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

Post by StanislavK » Mon 31 Jan 2011 17:13

Thank you for your report, we've reproduced the error. We will investigate it and inform you about the results as soon as possible.

As a workaround, you can perform the update before the deletion with two calls of SubmitChanges(). To ensure that either both changes were performed or both were not, you can, e.g., explicitly start a transaction on the DataContext's connection:

Code: Select all

[myDataContext].Connection.Open()
Dim transaction = [myDataContext].Connection.BeginTransaction()

(perform updates)
[myDataContext].SubmitChanges()

(perform deletions)
[myDataContext].SubmitChanges()

transaction.Commit()
JIC: the recommended way of assigning a 'detail' entity to another 'master' entity is to change the EntityRef property instead of the master_id field. The point is that LinqConnect controls graph consistency with the help of EntityRef properties, whereas changing the master_id field directly may lead to a situation when a 'detail' refers a 'master' that does not have this 'detail' in its Details collection. For more information about this, please refer, e.g., to
http://msdn.microsoft.com/en-us/library ... ql_topic24

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

Post by StanislavK » Thu 10 Feb 2011 17:41

We have fixed the error with incorrect order of performing update commands. The fix is available in the new 2.20.12 version of LinqConnect (and in the new builds of the data providers as well). The new build can be downloaded from
http://www.devart.com/linqconnect/download.html
(the trial and free versions) and from Registered Users' Area (for users with active subscription only):
http://secure.devart.com/

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

Post Reply