Use TypeContainedAttribute to trick databinding

Posts   
 
    
pat
User
Posts: 215
Joined: 02-Mar-2006
# Posted on: 29-Mar-2010 17:27:15   

Hi,

I use this inheritance hierarchy: ShotEntity based on CoreEntity TaskEntity based on CoreEntity ShotEntity can have TaskEntity as a child.

There are a lot more classes and the relationships need to be dynamic that's why ShotEntity doesn't have a Tasks property but rather CoreEntity has a porperty called CoreChildren which is a collection of CoreEntity objects.

Now to be able to bind this collection I would like to use the following so that the Grid can databind the sub type properties correctly:

[TypeContainedAttribute(typeof(MyTaskEntity))]
public override EntityView2<CoreEntity> ChildrenAsTasks
{
    get
    {
        EntityCollection<CoreEntity> toReturn = base.CoreChildren;
        toReturn.EntityFactoryToUse = new MyTaskEntityFactory();
        return toReturn.CreateView(CoreFields.EntityTypeId == 2) as EntityView2<CoreEntity>;
        }
}

[TypeContainedAttribute(typeof(MyShotEntity))]
public override EntityView2<CoreEntity> ChildrenAsShots
{
    get
    {
        EntityCollection<CoreEntity> toReturn = base.CoreChildren;
        toReturn.EntityFactoryToUse = new MyShotEntityFactory();
        return toReturn.CreateView(CoreFields.EntityTypeId == 3) as EntityView2<CoreEntity>;
        }
}

So my question is if you see any problems with this approach? wink

Thanks, Patrick

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 30-Mar-2010 04:28:16   

It seems ok. However, you have to be careful how are you prefetching such child entities. Are you using Polymorphic prefetchPaths?

David Elizondo | LLBLGen Support Team