Inherited Entities

Posts   
 
    
jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 10-Feb-2005 01:06:18   

I'm looking for the recommended way to ensure that a derived entity is returned by various base entitities in the Adapter scenario. I have an "Address" entity that I've extended to include a "Parse" method and an overriden "ToString" method that returns a formatted version of the complete address.

I've created the necessary inherited entity and factory classes and now I want to make sure that whenever I need to reference this new "MyAddress" entity via other entities, it returns the correct type.

For example, I have a "PurchaseOrder" entity that needs to return 3 of these "MyAddress" entities: BillToAddress, ShipToAddress, and VendorAddress. So, I've extended the generated PurchaseOrder entity and created "MyPurchaseOrder". Do I just copy the code laid out in the generated base class? If so, what do I do about "SetupSyncBillToAddress(value)" which is typed to the base class?:


Public Class MyPurchaseOrderEntity
Inherits PurchaseOrderEntity

Private _billToAddress as MyAddressEntity
...

Public Property BillToAddress as MyAddressEntity
Get
Return _billToAddress
End Get

Set (value as MyAddressEntity)
                If MyBase.IsDeserializing Then
                    SetupSyncBillToAddress(value)
                Else
                    If value Is Nothing Then
                        If Not _billToAddress Is Nothing Then
                            
                            _billToAddress.UnsetRelatedEntity(Me, "PurchaseOrder")
                            
                            
                        End If
                    Else
                        
                        CType(value, IEntity2).SetRelatedEntity(Me, "PurchaseOrder")                        
                    End If
                End If
End Set
End Property
End Class

On a related note, it seems that when setting a related entity such as PurchaseOrder.BillToAddress to NULL, it does not set the related FK to NULL to match. Is this expected behavior? I can't remember if auto-syncing PK/FKs for entities was implemented in Adapter...

Thanks.

Jeff...

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 10-Feb-2005 09:18:00   

jeffreygg wrote:

I'm looking for the recommended way to ensure that a derived entity is returned by various base entitities in the Adapter scenario. I have an "Address" entity that I've extended to include a "Parse" method and an overriden "ToString" method that returns a formatted version of the complete address.

I've created the necessary inherited entity and factory classes and now I want to make sure that whenever I need to reference this new "MyAddress" entity via other entities, it returns the correct type.

For example, I have a "PurchaseOrder" entity that needs to return 3 of these "MyAddress" entities: BillToAddress, ShipToAddress, and VendorAddress. So, I've extended the generated PurchaseOrder entity and created "MyPurchaseOrder". Do I just copy the code laid out in the generated base class? If so, what do I do about "SetupSyncBillToAddress(value)" which is typed to the base class?:

The purchageorder - address relations where these fields are mapped on, are these present in the project? If so, these fields are already there, but return AddressEntities, and in your derived class the template will have added properties which hide the base class properties and return MyAddressEntity instances.

On a related note, it seems that when setting a related entity such as PurchaseOrder.BillToAddress to NULL, it does not set the related FK to NULL to match. Is this expected behavior? I can't remember if auto-syncing PK/FKs for entities was implemented in Adapter...

No that's not done yet. If you set an FK field to a different value, it will make a reference to a related entity based on that FK field be set to null.

Frans Bouma | Lead developer LLBLGen Pro
jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 11-Feb-2005 18:42:04   

Otis wrote:

The purchageorder - address relations where these fields are mapped on, are these present in the project? If so, these fields are already there, but return AddressEntities, and in your derived class the template will have added properties which hide the base class properties and return MyAddressEntity instances.

But, there's some serialization code in the base class's Setter. If I Shadow the Property do I need to duplicate that serialization code?


Public Class MyPurchaseOrderEntity
Inherits PurchaseOrderEntity

Private _billToAddress as MyAddressEntity
...

Public Shadows Property BillToAddress as MyAddressEntity
Get
    Return _billToAddress
End Get

Set (value as MyAddressEntity)
    _billToAddress = value
End Set
End Property
End Class

I'm not calling back down into the base class because I'm Shadowing and using a different return type, so what about the deserialization code and the SetRelatedEntity and UnSetRelatedEntity stuff?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 12-Feb-2005 21:04:11   

You should call the base properties. See the adapterExtendedEntityTemplates for details.

Frans Bouma | Lead developer LLBLGen Pro
jeffreygg
User
Posts: 805
Joined: 26-Oct-2003
# Posted on: 14-Feb-2005 19:02:04   

Otis wrote:

You should call the base properties. See the adapterExtendedEntityTemplates for details.

I'll check them out. Thanks.