Transactions and Complex BO relationships


Author
Message
Andria Jensen
Andria Jensen
Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)Advanced StrataFrame User (600 reputation)
Group: Forum Members
Posts: 336, Visits: 497
Ok, I'm going to give a scenario and would like some feedback on the best way to accomplish this. 

I have a transaction which uses something like 10 business objects and needs to save them all out at the end of a bunch of processing.  There are parent/child relationships with almost all of these BO's.  However, one BO may be involved in a few parent child relationships.  This means in one case it may have a certain parent where in another case it would have a different parent.  Whether this is good design or not, that's what I have to work with...

Now, I know that there are issues when mixing the parent/child relationships and transactions on BOs.  Should I just assign the foreign keys manually in these cases?  If so, how do I do this correctly?  At the time I need to assign the foreign key the primary key on the parent hasn't been saved so it has a negative value in it still.  What is the best way to approach a situation like this?  I feel like I keep running into dead-ends.

Reply
StrataFrame Team
S
StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)StrataFrame Developer (6.5K reputation)
Group: StrataFrame Developers
Posts: 3K, Visits: 2.5K
When you have multiple relationships like that, your best bet is to probably handle the relationships manually.  If you are saving on a transaction, then you will want to make sure that you either only call Save() on the bottom of the relationship tree so that the call gets cascaded up, or set the ParentBusinessObject to Nothing on your business objects before saving them and then set them back. 

Now, when you have a relationship that isn't automatically managed by the ParentBusinessObject/ParentRelationship properties, you can use the GetPostSavePrimaryKeyValue() method on the business object.  After each save of a business object, that method internally stores a dictionary of the pre/post save primary key values, so it might have (-1, 1480) and (-2, 1481) where the 1480 and 1481 were assigned by the server for the two records that had -1 and -2 in the BO respectively.  After the save, if you pass -1 to the GetPostSavePrimaryKeyValue(), it will return to you the 1480 for you to use anywhere you need.  The dictionary only contains the values for the last Save() call, so make sure that you get the values you need before calling Save() on the business object again.

GO

Merge Selected

Merge into selected topic...



Merge into merge target...



Merge into a specific topic ID...





Similar Topics

Reading This Topic

Login

Explore
Messages
Mentions
Search