Relation using entity SubType

Posts   
 
    
colincsb
User
Posts: 18
Joined: 01-Nov-2006
# Posted on: 26-Nov-2007 06:26:26   

I am using LLBLGen 2.5 with the SelfServicing model.

I have the following entities and relations:

RequestEntity ------- LoginUserEntity | ClientUserEntity ---------- ClientEntity

The LoginUserEntity hierarchy is held in a single table. ClientUserEntity is an abstract SubType of LoginUserEntity that has a number of concrete SubTypes for various user types. The relation between ClientEntity and ClientUserEntity is based on a PK Field of ClientEntity that is held in the ClientUserEntity SubType (not in LoginUserEntity).

I had previously used the following code to in PerformSelect() for a datasource to select a list of RequestEntities related to a particular ClientEntity:


            ClientUserEntity clientUser = getCurrentClient();

            IPredicateExpression filter = new PredicateExpression();
            RelationCollection relations = new RelationCollection();

            // link to ClientEntity
            relations.Add(RequestEntity.Relations.LoginUserEntityUsingUserId);
            relations.Add(ClientEntity.Relations.ClientUserEntityUsingClientId);
            filter.Add(ClientFields.ClientId == clientUser.ClientId);

            e.ContainedCollection.GetMulti(filter, 0, sort, relations, pageNumber, pageSize);
            

However, I now find that this code gives me a runtime error:

Relation at index 1 doesn't contain an entity already added to the FROM clause. Bad alias?

Commenting out the relation from ClientEntity to ClientUserEntity (and the filter) removes the problem but (obviously) performs the wrong selection.

This code definitely worked with version 2.0 of LLBLGen. I have upgraded to version 2.5 some time ago and just discovered this erorr .. I don't know whether the upgraded version is the problem.

I tried deleting and regenerating all of my LLBLGen generated code but this did not make a difference.

I looked everywhere for an explicit method of including the ClientUserEntity in the query and tried using GetSubTypeRelation() but when I did this I just got a different error.

What am I missing?

Thanks.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 26-Nov-2007 09:54:28   

Instead of:

relations.Add(ClientEntity.Relations.ClientUserEntityUsingClientId);

Please try:

relations.Add(ClientUserEntity.Relations.ClientEntity...);
colincsb
User
Posts: 18
Joined: 01-Nov-2006
# Posted on: 27-Nov-2007 20:07:39   

Thanks!! That worked ... does that mean the "direction" of the relation that is used (and/or the order in which they are added) is important?

How should I structure this to best optimise my code?

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 28-Nov-2007 10:52:53   

Yes direction and order is important.

For example if you want to make a query where you are selecting from customers but you want to join orders and orders details.

Then you should first add a relation from Customer to Order. And then you should add a relation from Order to OrderDetail.