IEntity2 from IEntityRelation

Posts   
 
    
arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 19-Jul-2008 17:19:21   

I'm using adapter, SqlServer, v2.6 latest.

I'm working at run time.

I have a IEntity2, let's call it x. From that I want to examine its related IEntity2s (if any). To be clear, I don't have any data in x and don't want to see any actual data in the related IEntity2; I want to examine the field names on the related entities.

I can get x.GetAllRelations(); to get its IEnityRelations. From a IEntityRelation I don't see a way to get the related IEntity2? I see that I can get the field name that holds the entity or collection in x from the relation but I don't think that helps me.

Edit

I now have the related IEntity2s using


List<IEntityCollection2> collections = x.GetMemberEntityCollections();
foreach (IEntityCollection2 x in collections)
                    {
                        IEntity2 entity2 = entityCollection2.EntityFactoryToUse.Create();
                    }

I think my question becomes: How do I match entity2 to the relations that have x at one end and entity2 at the other?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 20-Jul-2008 20:01:55   

Hi Al,

Here is addressed a similar question: http://llblgen.com/TinyForum/Messages.aspx?ThreadID=13405

David Elizondo | LLBLGen Support Team
arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 20-Jul-2008 22:08:31   

Thanks, the process is a little convoluted, but it seems to work, my unit tests are passing.

I wonder why the relation object doesn't know it's beginning and ending entities directly?

Walaa avatar
Walaa
Support Team
Posts: 14994
Joined: 21-Aug-2005
# Posted on: 21-Jul-2008 10:11:36   

I wonder why the relation object doesn't know it's beginning and ending entities directly?

Because it's redundant info: a relation is between tuples (with 1 or more fields) of fields, which are part of an entity. To store the entity info there as well is a bit overkill. A field contains its entity name though .

arschr
User
Posts: 894
Joined: 14-Dec-2003
# Posted on: 21-Jul-2008 13:08:44   

A field contains its entity name though .

What would be the impact of it containing (a pointer to) it's entity instead? (for vNext of course) Seems it would save some space, but might impact object lifetime.

Any way thanks, I've gotten my code working. I may look into a template to generate this info rather than having to discover it.