Inserting parent and child objects and transactions

Inserting parent and child objects and transactions

Old forum URL: forums.lhotka.net/forums/t/8190.aspx


tiptop posted on Monday, December 21, 2009

Hello All

Hope you can point me in the right direction.

After a lot of debugging and putting break points everywhere, I finally discovered why my form was not saving.

I have a form that has :

Parent1
---Child 1
------Child2

The data portal child insert is working fine on Child 2 and new identity value is returned. But when I come to come insert Child 1, it fails on a referential integrity error. This is because the whole insert ( starting at Parent 1 ) is working via a transaction. Therefore, even though Child 2 has inserted a record correctly and it has returned a new id. If Child 1 uses the new ID it fails, because it doesn't actually physically exist in the foreign key table.

How do I get around this? Any hints would be appreciated.


PS : For any other newbies to CSLA, I had an initial error where the parent object was coming back with a "Is not valid" error during the Save process. I finally worked out that each property must have a valid value as defined by the database schema.

tiptop replied on Monday, December 21, 2009

Ok. I sussed it out.

You need to use " using (BypassPropertyChecks)" in your DataPortal_Insert method.

This doesn't do the referential integrity checks for each child but it should still work as one whole transaction.

Copyright (c) Marimer LLC