linq - Dynamic Expression Building Error -


i have searched lot regarding issue wrong here

shorter version of code /// companyid  integer type value here 220     var cond1 = buildexpression(companyid);     var acntlst=entities.accounts.where(cond).tolist(); 

account class querying against account collection

buildexpression function

 private static expression<func<account, bool>> buildexpression(string companyid)   {     var paramexp = expression.parameter(typeof (account), "p");      var proprty = typeof(account).getproperty("companyid");      var prpexp = expression.property(paramexp, proprty);       var varexp = expression.variable(typeof(int32), companyid);      var cond1 = expression.equal(prpexp, varexp);       return expression.lambda<func<account, bool>>(cond1,paramexp);     } 

error message is

the parameter '220' not bound in specified linq entities query expression 

expression.variable(typeof(int32), companyid); 

this creates variable named "220".
never declared variable or assigned value.

instead, want expression.constant, takes value , returns expression has value.
(you need parse string int)

however, don't need build hand @ all.

instead, should write return => a.companyid == companyid


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -