I thought I was having a completely different issue but in playing around with this I believe I found my true problem. However, I don't know why it's happening.
I'm using PredicateBuilder (LinqKit) to build dynamic queries to pull data based on user input.
Here's where I assign the variables for searching:
var pb = PredicateBuilder.New<UserData>(true);
foreach (var item in lstParams)
{
string name = "City";// item.spName;
string val = "Port";// item.spValue;
pb = pb.And(ud => ud.VarName.Contains(name)).And(ud => ud.VarValue.Contains(val));
}
The item.spName equals "City" and item.spValue equals "Port". When I run the above code, I do not see "City" and "Port" but instead I see references to the variables:
{ud => (ud.VarName.Contains(value(DAL.DBAccessMethods.DataAccess+<>c__DisplayClass78_0).name) AndAlso ud.VarValue.Contains(value(DAL.DBAccessMethods.DataAccess+<>c__DisplayClass78_0).val))}
In playing around with this, I hardcoded the variables into the PredicateBuilder and the names show up in inspection and the query works.
pb = pb.And(ud => ud.VarName.StartsWith("City"));
pb = pb.And(ud => ud.VarValue.StartsWith("bl"));
On inspection I see this:
{ud => (ud.VarName.StartsWith("City") AndAlso ud.VarValue.StartsWith("Port"))}
How do I get variables into the PredicateBuilder object?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…