Problem creating predicate expressions across relations

Posts   
 
    
JAgiato
User
Posts: 4
Joined: 12-Jul-2005
# Posted on: 20-Jul-2005 17:12:18   

Hello,

In an application there is a class which takes user selections, creates the appropriate predicate expressions and returns a RelationPredicateBucket. The problem I am having is if I wish to create a predicate expression that compares say the value of x (say for example a string) which contains PhoneNumber, with the value of PhoneNumber which is on a related table.

For example:

We have two tables Client and Contact (this table has an attribute called PhoneNumber)

We wish to be able to create a predicate expresson in the following way:


IPredicateExpression phoneExpression = new PredicateExpression();
if(selections.PhoneNumber != String.Empty)
{
    phoneExpression.Add(PredicateFactory.CompareValue(ClientFieldIndex.Contact.PhoneNumber, ComparisonOperator.Equal, selections.PhoneNumber));
                
    if(count != zero)
    {
        bucket.PredicateExpression.AddWithAnd(phoneExpression);
    }
    else
    {
        bucket.PredicateExpression.Add(phoneExpression);
    }
    ++count;
}

Upon compilation I recieve errors relating to ClientFieldIndex not being able to find Contact or PhoneNumber. There is no reference to ContactFieldIndex either on ClientFieldIndex. How may I create such functionality?

Thanks!

Jon

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39933
Joined: 17-Aug-2003
# Posted on: 20-Jul-2005 19:00:31   

JAgiato wrote:

Hello,

In an application there is a class which takes user selections, creates the appropriate predicate expressions and returns a RelationPredicateBucket. The problem I am having is if I wish to create a predicate expression that compares say the value of x (say for example a string) which contains PhoneNumber, with the value of PhoneNumber which is on a related table.

For example:

We have two tables Client and Contact (this table has an attribute called PhoneNumber) We wish to be able to create a predicate expresson in the following way:


IPredicateExpression phoneExpression = new PredicateExpression();
if(selections.PhoneNumber != String.Empty)
{
    phoneExpression.Add(PredicateFactory.CompareValue(ClientFieldIndex.Contact.PhoneNumber, ComparisonOperator.Equal, selections.PhoneNumber));
                
    if(count != zero)
    {
        bucket.PredicateExpression.AddWithAnd(phoneExpression);
    }
    else
    {
        bucket.PredicateExpression.Add(phoneExpression);
    }
    ++count;
}


IPredicateExpression phoneExpression = new PredicateExpression();
//if(selections.PhoneNumber != String.Empty)
// use length compare, is much faster
if(selections.PhoneNumber.Length <=0)
{
    phoneExpression.Add(
        PredicateFactory.CompareValue(ContactFieldIndex.PhoneNumber, ComparisonOperator.Equal, selections.PhoneNumber));

    // you don't have to test for count, Add defaults to And, and AddWithAnd checks if there is already a predicate
    // so will cope with that, so either one will do.
    bucket.PredicateExpression.Add(phoneExpression);
}

You have to specify the ContactFieldIndex, you can't traverse from one field index to another, it's an enum for the field definition in an entity. If you're fetching Client entities, and you want to filter on Contact.PhoneNumber, you have to specify the relation ClientEntity.Relations.ContactEntityUsingContactID (or similar) using the bucket.RelationCollection as well.

Frans Bouma | Lead developer LLBLGen Pro
JAgiato
User
Posts: 4
Joined: 12-Jul-2005
# Posted on: 20-Jul-2005 20:22:52   

Thanks Otis. I figured this out a bit ago but will use those more performant options described.

Best,

Jon