How to get list of Entities 2 relations away?

Posts   
 
    
Posts: 1268
Joined: 10-Mar-2006
# Posted on: 14-Mar-2006 22:15:00   

If you have the following relationship:

TableA --(1:n)--> TableB --(1:n)--> TableC

I now want to display all Entities from TableC in a Grid. How do I do that?

I can get a list of TableC for any Entity in TableB: EntityA.EntityCollectionB[x].EntityCollectionC

In SQL it would be simple select whatever from TableC join TableB on TableB.TableBKey=Tablec.TableBKey join TableA on TableA.TableAKey=TableB.TableAKey

And I could of course define a view and scope it, or a stored procedure, but thought I would be able to do it with LLBLGen objects?

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 15-Mar-2006 03:10:11   
EmployeeCollection employees = new EmployeeCollection();
IPredicateExpression filter = new PredicateExpression();
filter.Add(CustomerFields.CustomerId == 1);
IRelationCollection relations = new RelationCollection();
relations.Add(CustomerEntity.Relations.DepartmentEntityUsingCustomerId);
relations.Add(DepartmentEntity.Relations.EmployeeEntityUsingDepartmentId);
employees.GetMulti(filter, relations);

This code should do it. TableA is customer, TableB is department and TableC is Employee

employees is a collection that you can then bind to your grid.

Posts: 1268
Joined: 10-Mar-2006
# Posted on: 15-Mar-2006 04:07:36   

I can try that, perhaps I was thinking about it all wrong.

I already have a TableA entity loaded. It has relations defined in the GUI (and hence code) to TableB. I was hoping I could get there using the relations I had setup in the GUI and was just missing something???

When I look at the relations in the GUI, I have relations Customer <--> Department <--> Employee (which all come from the database of course).

Can the GUI not define an 'Employees' collection off of 'CustomerEntity'? (which is what you setup in code I guess?) I see some of the automatic relationships sometimes have 'via' in them, but do not know how to get that setup.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Mar-2006 14:49:45   

If you want to do it from the LLBLGen Pro designer, then you may create a Typed List.

Posts: 1268
Joined: 10-Mar-2006
# Posted on: 15-Mar-2006 15:23:45   

So there is no way to have myEntity.Somecollection, where Somecollection is more than one relation away?

If I used a TypedEntity, I would then want to relate that to MyEntity so that I can do the above.

Is that code above the 'way' to do this - I would think it would be a designer option or something?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 15-Mar-2006 15:46:24   

The designer can detect the following relations:

1- [A] m:1 [B] 2- [A] 1:m [B] 2- [A] m:n [B] (which has the via word in the name) = [A] 1:n [C] && [C] m:1 [B]

bclubb
User
Posts: 934
Joined: 12-Feb-2004
# Posted on: 16-Mar-2006 02:33:59   

There isn't a way to do it in the designer using two 1:m relationships. You could put the code I have in the usercode region to return the collection that you are refering too. If you want to do this then I would implement it as another collection by hand by using other related collections as an example in your TableA entity class.

Posts: 1268
Joined: 10-Mar-2006
# Posted on: 18-Mar-2006 00:43:39   

No problem - I just added a property to my entity to do the relation as you have shown me and works like a champ.

Thanks.