Query question

Posts   
 
    
ianvink
User
Posts: 394
Joined: 15-Dec-2006
# Posted on: 10-Jan-2007 01:44:12   

I have a set of entities Continent Country City

with obvious relationships of 1:m

I need all the Continents where they have a City.Name = "London"

How would I set up a Predicate for that?

I tried this:

IPredicateExpression select = new PredicateExpression();
select.AddWithOr(CityFields.Name == "London");
            
IRelationCollection relations = new RelationCollection();
relations.Add(ContinentEntity.Relations.CountryUsingContinent_Id);
relations.Add(CountryEntity.Relations.CityEntityUsingCountry_Id);

Is this the optimal way to do it?

Ian

psandler
User
Posts: 540
Joined: 22-Feb-2005
# Posted on: 10-Jan-2007 05:23:22   

ianvink wrote:

IPredicateExpression select = new PredicateExpression();
select.AddWithOr(CityFields.Name == "London");
            
IRelationCollection relations = new RelationCollection();
relations.Add(ContinentEntity.Relations.CountryUsingContinent_Id);
relations.Add(CountryEntity.Relations.CityEntityUsingCountry_Id);

Looks good to me. You didn't include all your code, so it's hard to say for sure (depends on what you are doing exactly). I'm also not clear on whether it worked or not?

Phil

Walaa avatar
Walaa
Support Team
Posts: 14995
Joined: 21-Aug-2005
# Posted on: 10-Jan-2007 08:24:13   

That's correct, that's how you formulate the WHERE clause and the JOINS. But now you have to use them both in your QUERY.