Andria Jensen (10/31/2007)
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.I assigned foreign keys manually. I have two nullable fields on a business object. One is a foreign key to a person/contact and the other is a foreign key to a supplier/company. When I go to save the address, before i actually call the Save method on the address object, I assign the ID from the correct parent (the ID of the current record in the parent object) in the code, then call save and send it the transactional flag and the key.
Basically, you have to save things one object at a time. I found it best to start at the top of my hierarchy and work my way down. For example, when I finished all the things I needed to do on the supplier/company, I'd save to the transaction. Then I started on the address object. Once you do the transactional save on the parent, you have your unique ID assigned and you can pull it for use in saving to your child object.
One thing I can recommend is not using the Business Layer Link Manager object to manage M2M relationships for this situation. I use it, but only when I'm in a view state. When it comes to saving/updating such complex relationships, the BLLM actually got in the way and made things very difficult because of events firing at various points.
Hope this helps...
Regards,
Peter