This simple PredicateBuilder example does not work - clueless?

I have attempted to follow the example for PredicateBuilder given in the help and I am getting this error:

variable 'f' of type 'LINQPad.User.Paramtrs' referenced from scope '', but it is not defined
for this:

var predicate = PredicateBuilder.False<Paramtrs>();
bool normalize = true;
string[] criteriaStr = { "district" };
foreach (var str in criteriaStr)
var temp = normalize?str.ToLower().Trim() : str;
predicate = predicate.Or< Paramtrs>(f => (normalize?f.FieldName.ToLower().Trim() : f.FieldName) == temp);  
Paramtrs**.Where (predicate).Dump();

The only difference I have made here is that I have forced the values to lowercase and trim because the database entries themselves may have inconsistent capitalization. Doubtless there is a smarter way to do that. However, with or without that normalization, the example does not work.

Paramtrs is a table in the database I am using. I know it exists and I know it has data.

This following bit as a C# expression does work from LinqPad.

from p in Paramtrs
where p.TableName=="bridge" && p.FieldName=="district" && p.Isactive==1
orderby p.OrderNum
select p

Ultimately I might want to apply a couple criteria. I am frankly lost here. Any guidance would be appreciated.


Sign In or Register to comment.