This question is locked. New answers and comments are not allowed.
Hello,
My question is in regards to how Open Access is handling identity colums with tables that have foreign references.
Say For example I have the following Persistent classes:
Is it possible to create a new Tmp object and add TmpChild object to the newly created in one Transaction?
Example:
This creates a foreign key error because the id does not exist when adding.
Or do we need to get the identity value returned then add the child values? This creates a problem because if the parent insert was successful and the child insert failed It requires that the parent insert now be deleted.
What's the best way to accomplish this?
Thanks,
Kareem
My question is in regards to how Open Access is handling identity colums with tables that have foreign references.
Say For example I have the following Persistent classes:
Public Class Tmp |
Private Dim _id As Integer ' pk identity field auto increment |
Private Dim _name As String |
Private Dim _tmpchild As IList(OF TmpChild) = New List(OF TmpChild)() |
End Class |
Class TmpChild |
Private Dim _tmpjobid As Integer ' pk |
Private Dim _value As String |
Private Dim _tmp As Tmp ' inverse Tmp._tmpChild |
End Class |
Is it possible to create a new Tmp object and add TmpChild object to the newly created in one Transaction?
Example:
Try
scope.Transaction.Begin()
parent = New Tmp
child = New TmpChild
parent.Name = "John Joe"
parent.children.Add(child) ' internally the new parent id would be assigned then should be used in adding the child object
scope.Add(parent)
scope.Add(child)
scope.Transaction.Commit()
Catch e As Exception
scope.Transaction.Rollback()
Finally
End Try
This creates a foreign key error because the id does not exist when adding.
Or do we need to get the identity value returned then add the child values? This creates a problem because if the parent insert was successful and the child insert failed It requires that the parent insert now be deleted.
What's the best way to accomplish this?
Thanks,
Kareem