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.