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.
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.