cjard
Well-known member
- Joined
- Apr 25, 2006
- Messages
- 7,081
- Programming Experience
- 10+
Using the well hammered example of Person:Address, I will describe my database structure:
2 DataTables, one for address, one for person details
ADDRESS_REF is the PK of the Address table (in combination with a work/home/etc specifier) and a same named column exists as the FK in Person
One person can have many addresses (home, work, etc)
The datarelation that exists is set up such that Person is the Parent table, and Address is the child table. The form is set up correctly such that the binding nav for addresses is bound to the relation, allowing browsing of multiple addresses for multiple people
When we insert these into a database, the addresses is inserted first, with a -1 as the address_ref. Seeing this, the stored procedure that performs the update calculates a proper ID for the address, inserts the record and transmits the proper ref back to the client via the same parameter.
At this point I manually inspect to see if it was -1 before and not -1 now.. I take the new value and iterate the customers table, changing all -1 for the new value. If i had to insert 2 people, one of them would be -1 and one would be -2 thus ensuring they dont overlap and keeping the client side datarelation happy.
Now, what I ask to know is if the relation can keep this in sync for me. Judging by the notion that relations care cascade only, i think this will be parent, down to child and hence the data is updated in the wrong order for this to occur.
What can I do to use an automatic keep-in-sync offered by the relation?
Additionally, if I perform the entire operation inside a Transactions.TransactionScope, and inserting the first lot of data succeeds but the second lot fails, will the transaction scope be able to correctly roll back both my client side dataset data, and the database data?
2 DataTables, one for address, one for person details
ADDRESS_REF is the PK of the Address table (in combination with a work/home/etc specifier) and a same named column exists as the FK in Person
One person can have many addresses (home, work, etc)
The datarelation that exists is set up such that Person is the Parent table, and Address is the child table. The form is set up correctly such that the binding nav for addresses is bound to the relation, allowing browsing of multiple addresses for multiple people
When we insert these into a database, the addresses is inserted first, with a -1 as the address_ref. Seeing this, the stored procedure that performs the update calculates a proper ID for the address, inserts the record and transmits the proper ref back to the client via the same parameter.
At this point I manually inspect to see if it was -1 before and not -1 now.. I take the new value and iterate the customers table, changing all -1 for the new value. If i had to insert 2 people, one of them would be -1 and one would be -2 thus ensuring they dont overlap and keeping the client side datarelation happy.
Now, what I ask to know is if the relation can keep this in sync for me. Judging by the notion that relations care cascade only, i think this will be parent, down to child and hence the data is updated in the wrong order for this to occur.
What can I do to use an automatic keep-in-sync offered by the relation?
Additionally, if I perform the entire operation inside a Transactions.TransactionScope, and inserting the first lot of data succeeds but the second lot fails, will the transaction scope be able to correctly roll back both my client side dataset data, and the database data?