How to get hold of RelationCollection for an Entity ??

Posts   
 
    
GoodGuy007
User
Posts: 3
Joined: 02-Feb-2006
# Posted on: 02-Feb-2006 02:45:24   

how to get hold of the relationCollection for an entity ??

I would like to loop through the RelationCollection for each relation and check for a specific type of the relation.

Using: - Adapter - .NET 1.1 - LLBL 1.0.20042.50729

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 02-Feb-2006 04:16:43   

myEntity.Relations will return the relations that any instance of myEntity would have. If this isn't what you mean just provide some more information. Maybe some pseudocode.

GoodGuy007
User
Posts: 3
Joined: 02-Feb-2006
# Posted on: 02-Feb-2006 18:22:19   

myEntity.Relations does not return a collection

here is sample code what I am trying ...

Dim myEntity As Object myEntity = Activator.CreateInstance(assemblyName, myEntityName).Unwrap

Dim myEntityRelations As RelationCollection = myEntity.relations

For Each myEntityRelation As EntityRelation In myEntity.relations If myEntityRelation.TypeOfRelation = RelationType.OneToOne Then .........

      End If

Next

this does not work as the myEntity.Realtions does not return a collection .....

Is there another way I can achive this ..... thanks !!

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 03-Feb-2006 03:19:44   

I'm sorry I wrote that completely wrong. Relations is a static propery of the EntityClasses.

GoodGuy007
User
Posts: 3
Joined: 02-Feb-2006
# Posted on: 03-Feb-2006 19:02:34   

that means there is no generic way to achive the EntityRelations ?

Thanks !!

Posts: 65
Joined: 07-Dec-2005
# Posted on: 03-Feb-2006 20:30:55   

GoodGuy,

With the default template files, no. This, I'm sure is for a variety of reasons. However, I needed something similar, and ended up modifying the template files to give me a helper class that provided me with a Hashtable of relations for a given entity. I passed in an EntityType and recieved back a Hashtable with the related EntityType as the key. Obviously, this is contingent on whether or not your relations can link the same two entities in different ways. For us, this was not an issue. However, if you do have more than one relation between two objects, this obviously won't work, since you would have duplicate keys.

I'm at home right now, so I unfortunately don't have the modified templates, but hopefully this will get you stared in the right direction.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39930
Joined: 17-Aug-2003
# Posted on: 05-Feb-2006 12:47:22   

If you want this info, indeed go as Adam says: write a simple template which constructs in a singleton this information for you. To see how to write such a singleton and initialization code, please check the InheritanceProvider class in helperclasses. The template can be pretty straight foward. The problem with relations though is: how to quickly find a relation ? There's not a single information element which identifies a relation, but multiple elements: - related entity - fk fields.

Frans Bouma | Lead developer LLBLGen Pro