filter is not working correctly

Posts   
 
    
youkebb
User
Posts: 14
Joined: 14-May-2009
# Posted on: 12-Feb-2010 22:11:11   

I am using an adapter to fill up a entity collection in a standard way. My entity field has a string property say address.

EntityCollection<MyEntity> entityCol = new EntityCollection<MyEntity>(); IRelationPredicateBucket filter = new RelationPredicateBucket(); filter.PredicateExpression.Add(myFields.Address.ToString().Trim() == ""); adapter.FetchEntityCollection(entityCol , filter);

the previous code gave me a compilation error complaining about the invalid argument in the IPredicate at filter.PredicateExpression.Add(myFields.Address.ToString().Trim() == ""); I know filter.PredicateExpression.Add(myFields.Address == "Some Address"); will work but i need to do some string manipulation with myFields.Address field. How can I do this in the filter? And hint will be appreciated. Thanks. James

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 13-Feb-2010 06:03:35   

Trim() in this context is just an In-Memory function that returns a string. So that couldn't be part of a predicate (string == string). Maybe you are misunderstanding this with linq function mappings.

Anyway you could use DBFuncionCalls. Something like:

EntityField2 trimField = myFields.Address;
trimField.ExpressionToApply = new DbFunctionCall("TRIM({0})", new object[] { myFields.Address });

filter.PredicateExpression.Add(trimField == "Some Address");
David Elizondo | LLBLGen Support Team
youkebb
User
Posts: 14
Joined: 14-May-2009
# Posted on: 16-Feb-2010 16:31:22   

[quotenick="daelmo"] thanks, DBFuncionCalls worked.