Inherited LLBLGEN entities and relationships

Posts   
 
    
Maxus
User
Posts: 76
Joined: 04-Aug-2006
# Posted on: 25-Feb-2008 07:14:01   

Hi great LLBLGEN folks!

Just a simple one, I'm not sure if this is even possible simple_smile

I was wondering how / if you can implement relationships in inherited classes.

for example i have:

DAL.EntityClasses.CustomerEntity <- Generated by LLBLGEN DAL.EntityClasses.OrderEntity <- Generated by LLBLGEN

I then inherit both these in a layer above:

BL.Entity.MyCustomerEntity <- Manually coded BL.Entity.MyOrderEntity <- Manually coded

How do I implement 1:1 and 1:M reationships in the inherited entities so they use the inherited entity classes?

for example

MyCustomerEntity returns a collection of MyOrderEntities instead of OrderEntities?

Does anyone have a quick example they could send me? (thats assuming its actually possible?)

I am using the adapter tasks.

Thanks! Alex

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 25-Feb-2008 11:09:18   

Please check the following thread for a similar discussion: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=10323

Maxus
User
Posts: 76
Joined: 04-Aug-2006
# Posted on: 26-Feb-2008 00:33:29   

Hi Walaa,

Thanks for that info, so it is possible to do. I reviewed the derived classes in my solution, but they dont seem to offer the relationships correctly:


/// <summary>
/// Gets the EntityCollection with the related entities of type 'MyStorageItemEntity' which are related to this entity via a relation of type '1:n'.
/// If the EntityCollection hasn't been fetched yet, the collection returned will be empty.
/// </summary>
[TypeContainedAttribute(typeof(MyStorageItemEntity))]
public override EntityCollection<StorageItemEntity> ChildStorageItems
{
                get
    {
        EntityCollection<StorageItemEntity> toReturn = base.ChildStorageItems;
        toReturn.EntityFactoryToUse = new MyStorageItemEntityFactory();
        return toReturn;
    }
}

Sholdn't that be returning a collection of EntityCollection<MyStorageItemEntity> as opposed to EntityCollection<StorageItemEntity>?



/// <summary>
/// Gets / sets related entity of type 'MyStorageItemEntity' which has to be set using a fetch action earlier. If no related entity
/// is set for this property, null is returned.
/// This property is not visible in databinded grids.
/// </summary>
[Browsable(false)]
public new virtual MyStorageItemEntity ParentStorageItem
{
    get { return (MyStorageItemEntity)base.ParentStorageItem; }
    set { base.ParentStorageItem = value;   }
}

When I try to access this property I just recieve a invalid cast exception.

How do I access the properties to return the correct type and avoid the cast exception?

Thanks! Alex

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Feb-2008 10:55:51   

When I try to access this property I just recieve a invalid cast exception.

How do I access the properties to return the correct type and avoid the cast exception?

Please post the code used to access this property. Also please post the exact exception text and stack trace.

Consider using a prefetchPath as shown in the following thread: http://www.llblgen.com/TinyForum/Messages.aspx?ThreadID=10800

Maxus
User
Posts: 76
Joined: 04-Aug-2006
# Posted on: 27-Feb-2008 03:27:27   

Hi Walaa,

The prefetch issue fixed it, thanks heaps!

-A