Custom entities in m:1 (or 1:1) relation during collection fetch

Posts   
 
    
BlackMamba avatar
BlackMamba
User
Posts: 34
Joined: 30-Apr-2004
# Posted on: 29-Mar-2005 15:57:59   

Hello, I've created my own entities subclassing the ones generated by LLBLGen pro because I need extra stuff in them and like the manual says it's possible to do this using inheritance.

When an entity has a one-to-many relation then a property for this relation is generated exposing an EntityCollection. When using subclassed entities the factory for this collection has to be set to the one which creates the subclassed entity instead of the original one. This work perfectly, but for many-to-one relations? My custom entities expose a property for many-to-one relations that expose my custom entity version instead of the original, for example:

LLBLGen:

Class ChildEntity Property Father as FatherEntity

my own: Class MyChildEntity Inherits ChildEntity Property Father as MyFatherEntity

The problem is, when an entity collection of MyChildEntity is fetched, the property Father does not contain an instance of MyFatherEntity (which is what I want) but of FatherEntity, so I would like to know if there's an extensibility point so that an instance of MyFatherEntity is inserted and if yes how should I do this.

Thanks a lot Simone

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 29-Mar-2005 16:33:24   

Please check if you call the base' class version of the property, because in there synchronization is setup. So in MyFatherEntity call base.FatherEntity for get/set.

Frans Bouma | Lead developer LLBLGen Pro
BlackMamba avatar
BlackMamba
User
Posts: 34
Joined: 30-Apr-2004
# Posted on: 30-Mar-2005 10:55:19   

Otis wrote:

Please check if you call the base' class version of the property, because in there synchronization is setup. So in MyFatherEntity call base.FatherEntity for get/set.

Yes I did check this and it's like you say. Infact I think I copied the code from derived class templates on the SVN you had setup or somewhere else I can't remember.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 30-Mar-2005 11:30:52   

So you call the base class' methods and no synchronization is taking place? Hmm.

Frans Bouma | Lead developer LLBLGen Pro
BlackMamba avatar
BlackMamba
User
Posts: 34
Joined: 30-Apr-2004
# Posted on: 30-Mar-2005 11:40:30   

Otis wrote:

So you call the base class' methods and no synchronization is taking place? Hmm.

Well don't know what you really mean by synchronization in this context. The property returns a valid instance but it's of the original type and not my derived type. here is the code used to generate properties for many-to-one relations:

Public Shadows Overridable Property [<%= relation.RelationEndPoint.Name %>]() As My<%= relation.RelationEndPoint.Name %>Entity
            Get
                Return CType(MyBase.<%= relation.UtilizingPropertyName %>, My<%= relation.RelationEndPoint.Name %>Entity)
            End Get
            Set
                MyBase.<%= relation.UtilizingPropertyName %> = value
            End Set
        End Property

The problem is that casting the value returned from the base property to my own derived entity fails with a cast exception because the base property does not return an instance of my derived entity. Hmmm.. actually I think I just understood what's going on. I'm using a prefetch path to fetch the entity so I guess I have to pass the appropriate factory to the prefetch element .. will let you know if this was the problem or not.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 30-Mar-2005 13:00:45   

Aha, you indeed have to do that. The derived entity classes for adapter have code which create proper prefetch path properties for derived entity classes as well so you don't have to pass in the factories yourself. You could have a look at those to update your own templates.

Frans Bouma | Lead developer LLBLGen Pro