Monday, 15 July 2013

c# - Dynamically generated lambda giving different result than regular lambda -



c# - Dynamically generated lambda giving different result than regular lambda -

i have problem dynamically generated compared regular lambda look in code. below code utilize generate dynamic lambda.

dynamic lambda c

var parameterexp = expression.parameter(typeof(t), "x"); var propertyexp = expression.property(parameterexp, propertyname); methodinfo method = typeof(string).getmethod("contains", new[] { typeof(string) }); var somevalue = expression.constant(propertyvalue, typeof(string)); var containsmethodexp = expression.call(propertyexp, method, somevalue); homecoming expression.lambda<func<t, bool>>(containsmethodexp, parameterexp);

lambda debug view

{x => x.name.contains("username")}

but when lambda in code this

x => x.name.contains("username");

i result. formattedtext variable used regular lambda.

{x => x.name.contains(value(test.businesslogiclayer.classbll+<>x__displayclass8).formattedtext)}

i utilize lambda on clause on iqueryable object. dynamic lambda generates sql in iqueryable no sql parameters. regular lambda causes sql have parameters. need generate parameters. looping through parameters alter contains can utilize total text search in sql server.

my questions is, there way dynamically generate lambda have exact same output regular lambda? or there improve way utilize total text search in entity framework 6?

since declaring value constant (expression.constant) guess ef generates sql without parameters, since knows constant can't change.

perhaps improve off generating lambda explicitly takes parameter it's input ?

var parameterexp = expression.parameter(typeof(t), "x"); var containsparameter = expression.parameter(typeof(string), "p"); var propertyexp = expression.property(parameterexp, propertyname); methodinfo method = typeof(string).getmethod("contains", new[] { typeof(string) }); var containsmethodexp = expression.call(propertyexp, method, containsparameter);

which generate

(x, p) => x.name.contains(p)

c# linq lambda entity-framework-6

No comments:

Post a Comment