Howto: PredicateExpressions for joined tables

Posts   
 
    
Ruudster
User
Posts: 33
Joined: 13-Apr-2005
# Posted on: 08-Dec-2005 10:28:47   

Hi,

got three tables (entities):

CarBrand

BrandId BrandDescription

CarModel

ModelId BrandId ModelDescription

CarType

TypeId ModelId TypeDescription Attr1 Attr2 AttrN

One CarBrand can have multiple CarModels. One CarModel can have multiple CarTypes.

I want to fetch an entityCollection of CarBrand, for all CarBrand entities that have corresponding CarModels, that have corresponding CarTypes with predefined attributes.

In other words: Get a list of all CarBrand entities, with CarTypes having Attr1=foo1 AND Attr2=foo2 AND AttrN=fooN

I know how to get this working using stored procedures, but don't like this approach. How can i accomplish this with PredicateExpressions? Could you provide an example for this?

Thanks, Ruudster

Ruudster
User
Posts: 33
Joined: 13-Apr-2005
# Posted on: 08-Dec-2005 12:52:53   

Found a way to do this.


Dim filter As New RelationPredicateBucket
filter.Relations.Add(MyBrandEntity.Relations.ModelEntityUsingBrandId)
 filter.Relations.Add(MyModelEntity.Relations.TypesEntityUsingModelId)

filter.PredicateExpression.Add(PredicateFactory.CompareValue(TypesFieldIndex.Attr1, ComparisonOperator.Equal, foo1))
filter.PredicateExpression.Add(PredicateFactory.CompareValue(TypesFieldIndex.Attr2, ComparisonOperator.Equal, foo2))

Dim adapter As New DataAccessAdapter
MyBrandCollection.EntityFactoryToUse = New MyBrandEntityFactory
adapter.FetchEntityCollection(MyBrandCollection, filter)


Hope this is the right way to do the trick.

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 08-Dec-2005 14:09:53   

You have go it right simple_smile