Saving Nested Entities

Posts   
 
    
jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 11-Feb-2005 19:37:04   

Hi, Frans. According to the documentation, this should be possible:


Dim lineItems as New EntityCollection(New POLineItemFactory)
Dim myPOLineItem as New POLineItemEntity
Dim myVendorItem as VendorItemEntity
Dim uow as New UnitOfWork2

myVendorItem = MakeNewVendorItem()

myPOLineItem.POLineItemID = Guiid.NewGuid
myPOLineItem.VendorItemID = myVendorItem.VendorItemID  '<---
myPOLineItem.VendorItem = myVendorItem '<---

lineItems.Add(myPOLineItem)

uow.AddCollectionForSave(lineItems)
uow.Commit(myAdapter,True)

I get an FK Violation between POLineItem.VendorItemID and VendorItem.VendorItemID. I thought the framework should determine that the new VendorItem should get saved first, then the POLineItem, but it doesn't seem that that's the case.

Also, the FK isn't synchronized automatically when I make the entity reference myPOLineItem.VendorItem = myVendorItem, which is why I also call myPOLineItem.VendorItemID = myVendorItem.VendorItemID. Is that because myVendorItem is new?

Thanks.

Jeff...

jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 11-Feb-2005 20:12:16   

Never mind. I found the "recurse" parameter on the overload for UnitOfWork2.AddCollectionForSave(). Sorry 'bout that.

Jeff...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 11-Feb-2005 20:22:22   

No problem, Jeff simple_smile

Frans Bouma | Lead developer LLBLGen Pro