Adding CustomFilter to TypedList

Posts   
 
    
JMuller
User
Posts: 19
Joined: 09-Mar-2009
# Posted on: 10-Mar-2009 17:17:35   

Hi,

I have a TypedList having a left join on a table. In the table i would like use this left join to add a CustomFilter. I have this code:


ProductViewTypedList vProduct = new ProductViewTypedList();
IRelationPredicateBucket filter = vProduct.GetRelationInfo();

PredicateExpression pExpr = new PredicateExpression();
pExpr.AddWithAnd(ProductPricesFields.ProductID== 1);

(filter.Relations[1] as IEntityRelation).CustomFilter = pExpr;

This works fine, but i don't really like the index number hardcoded, because what if the TypedList changes, i will have to remember that i put a "1" somewhere, which I will forget most likely simple_smile .

So my question: Is there another way to get the right relation?

Thnx in advance.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 11-Mar-2009 05:48:02   

JMuller wrote:

So my question: Is there another way to get the right relation?

The other way I see is instantiate the relation and then use it to modify the custom filter:

ProductViewTypedList vProduct = new ProductViewTypedList();

IEntityRelation theRealtion = Product.Relations....

IRelation = someRelationUsedInTV;
someRelationUsedInTV.CustomFilter = ...
David Elizondo | LLBLGen Support Team
JMuller
User
Posts: 19
Joined: 09-Mar-2009
# Posted on: 11-Mar-2009 09:20:55   

daelmo wrote:

JMuller wrote:

So my question: Is there another way to get the right relation?

The other way I see is instantiate the relation and then use it to modify the custom filter:

ProductViewTypedList vProduct = new ProductViewTypedList();

IEntityRelation theRealtion = Product.Relations....

IRelation = someRelationUsedInTV;
someRelationUsedInTV.CustomFilter = ...

Hi, thnx for your suggestion, but how do i get the relation used in the TypedList? and pass it to the RelationPredicateBucket?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 11-Mar-2009 09:38:06   

Use the TypedList.GetRelationInfo() method.

JMuller
User
Posts: 19
Joined: 09-Mar-2009
# Posted on: 11-Mar-2009 09:47:30   

Walaa wrote:

Use the TypedList.GetRelationInfo() method.

Which i used in my first post, but i would like to use another way, instead of the index from GetRelationInfo().

daelmo suggested another way, but i can't see how to implement that .

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 11-Mar-2009 10:09:29   

I'm not sure about David's suggestion, but you can loop on the returned relations and check on the correct one based on the PK and FK used. (might be a lengthy operation but avoids the use of the index.)

JMuller
User
Posts: 19
Joined: 09-Mar-2009
# Posted on: 11-Mar-2009 12:16:25   

Walaa wrote:

I'm not sure about David's suggestion, but you can loop on the returned relations and check on the correct one based on the PK and FK used. (might be a lengthy operation but avoids the use of the index.)

That worked! Thnx alot.