Create relation based on the LLBL relation name

Posts   
 
    
nada
User
Posts: 8
Joined: 07-Feb-2008
# Posted on: 03-Mar-2008 23:11:56   

Is it possible if I know the LLBL relation name to add the relation at runtime? So basically, if there is a relation named OrderDetailEntityUsingOrderID, is there a way to instantiate the relationship in code based on the name?

If so, could you please give a small code snippet...thanks.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 04-Mar-2008 01:45:52   

I don't know a direct way, but you can use reflection:

System.Reflection.PropertyInfo property =  CustomerEntity.Relations.GetType().GetProperty("OrderEntityUsingCustomerId");
IEntityRelation rel = (IEntityRelation) property.GetValue(CustomerEntity.Relations, null);
David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39903
Joined: 17-Aug-2003
# Posted on: 04-Mar-2008 10:53:38   

In v2.5: List<IEntityRelation> relations = entity.GetAllRelations();

then loop through the IEntityRelation objects and find the IEntityRelation which has the property 'MappedFieldName' set to the name you're looking for.

Frans Bouma | Lead developer LLBLGen Pro