Enitity Relation mapping

Posts   
 
    
kemo
User
Posts: 5
Joined: 13-Feb-2006
# Posted on: 13-Feb-2006 18:38:58   

Hi all. (Using Adapter, SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll, .NET 2005)

I want to get the corresponding relation for an entity property in an entity.

A simple example for my question would be the following:

OrderEntity CustomerEntity customer //entity property for customerId field ProductEntity product //entity property productId field

OrderEntity.Relations.CustomerEntityUsingCustomerId OrderEntity.Relations.ProductEntityUsingProductId

I want to find the related entity property (which is CustomerEntity) at runtime from the EntityRelation object.

Rephrasing the question "Given an EntityRelation for an entity type I want to find the related property for that entity type"

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 14-Feb-2006 03:14:01   

That info isn't stored in the generated code. You can attempt to solve this by generating a template possibly. Let us know if you have any issues with the template creation.

kemo
User
Posts: 5
Joined: 13-Feb-2006
# Posted on: 14-Feb-2006 10:32:39   

Then I should ask if there is a way to map the entities and the fields specifying that entity.

OrderEntity CustomerEntity customer //entity property for customerId field ProductEntity product //entity property for productId field

I need the mapping between productId specified by product property in the OrderEntity class. If I can get this information then maybe I can use this information to get the corresponding EntityRelation for this field. From the GetFKEntityFieldCore(int index) method. But I could'nt find a way to do this.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 14-Feb-2006 11:54:02   

You tried creating the relation in the designer? Sorry for my misunderstanding, but I have a bit of a problem understanding which relations exactly you want to create. flushed

You want to define the relation Order.ProductId m:1 Product.ProductId ?

If so, you can do that in the designer. You can also do that in code, but it's more easier to do it in the designer.

Frans Bouma | Lead developer LLBLGen Pro
kemo
User
Posts: 5
Joined: 13-Feb-2006
# Posted on: 14-Feb-2006 12:56:06   

Ok when I re-read the message it was a bit misunderstandablesimple_smile Sorry for that. The case is I do not want to create a relation; I already have it. I want to get the property for this relation's FK side.

Here's what I really want to do. I have a relation and I want to know the corresponding property for it at runtime. I have the following entity:

OrderEntity CustomerEntity **Customer **{get ; set;}//entity property for customerId field ...//some other fields/properties.

I have also the below relation that in fact states an order has a relation with customer entity. OrderEntity.Relations.CustomerEntityUsingCustomerId

Is there a way to find from an EntityRelation object (for example OrderEntity.Relations.CustomerEntityUsingCustomerId) , the corresponding entity property (OrderEntity.Customer in this case) at runtime. Programatically I want to do something like

foreach (EntityRelation relation in RelationCollection){ relation.GetRelatedEntityPropertyName(); }

which should return the "[b]Customer[/b]" string when relation is equal to OrderEntity.Relations.CustomerEntityUsingCustomerId.

There is also a code like this in the OrderEntity Class:

private void SetupSyncCustomer(IEntity2 relatedEntity) { DesetupSyncCustomer(true); if(relatedEntity!=null) { _customer = (CustomerEntity)relatedEntity; _customer.ActiveContext = base.ActiveContext; _customer.AfterSave+=new EventHandler(OnEntityAfterSave); **base.SetEntitySyncInformation("Customer", _customer, OrderEntity.Relations.CustomerEntityUsingCustomerId);** } }

That information is what I need but I can't get it .

Hope I was clear this time.

Consider below as a second question: If there is no way to do this at least I want to get a field's related property. For example I have customerId field and Customer property inside an OrderEntity. I have this field at runtime and I want to get the corresponding entity property for this

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 14-Feb-2006 15:06:22   

Refering to the LLBLGen Pro Reference Manual.

In the EntityRelation class, you have 2 public properties: AliasFKSide Alias value for the entity which is on the FK side of the relation. Determined from the relation type and the pk/fk fields

AliasPKSide Alias value for the entity which is on the PK side of the relation. Determined from the relation type and the pk/fk fields

These might help you.

kemo
User
Posts: 5
Joined: 13-Feb-2006
# Posted on: 28-Feb-2006 10:45:38   

Walaa wrote:

Refering to the LLBLGen Pro Reference Manual.

In the EntityRelation class, you have 2 public properties: AliasFKSide Alias value for the entity which is on the FK side of the relation. Determined from the relation type and the pk/fk fields

AliasPKSide Alias value for the entity which is on the PK side of the relation. Determined from the relation type and the pk/fk fields

These might help you.

These two seem to be empty strings. Is there a point where these two are filled or should I do something to fill these two properties?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 28-Feb-2006 16:08:46   

~~Ok, if those was empty.

Try to use GetPKFieldPersistenceInfo() & GetFKFieldPersistenceInfo() methods of the IEntityRelation.

Then use the SourceObjectName of the returned IFieldPersistenceInfo.~~

(edit) I was wrong

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 28-Feb-2006 16:49:11   

What you want can't be achieved with the current generated code, as the information you want isn't stored in the EntityRelation object.

You can achieve this by creating a small include template which you bind to Custom_EntityAdapter templateID in a custom template set. (see the documentation how to extend the generated code with an include template). In the small template, you create a switch statement which accepts an entity relation and returns the name. Beware, comparing entityrelations is difficult (fields have to match, obeyweakrelations has to match, relation type has to match), as Equals isn't implemented on EntityRelation (no need for it in the current framework).

If there is no way to do this at least I want to get a field's related property. For example I have customerId field and Customer property inside an OrderEntity. I have this field at runtime and I want to get the corresponding entity property for this

That's always equal to the fieldname, so CustomerId .

Frans Bouma | Lead developer LLBLGen Pro
kemo
User
Posts: 5
Joined: 13-Feb-2006
# Posted on: 06-Mar-2006 16:43:06   

Ok. Checking the templates helped me. I solved the issue by editing them. Thanks for your help.