我目前有LAMBDA Expresion:http://pastebin.com/ZGCiQdHe查詢三重選擇
,我得到的ArgumentException在53線 http://msdn.microsoft.com/en-us/library/bb340145(v=vs.90).aspx
var lExpresion = Expression.Lambda<Func<TEntity, bool>>(body, parametrsNumber, parametrsTyp, parametrsLp);
,可是我不明白我做錯了。
我想:
WHERE ((twr_gidnumer =1 and twr_gidtyp = 1 and twr_gidlp = 1) OR
(twr_gidnumer =1 and twr_gidtyp = 1 and twr_gidlp = 2))
--ANSWERR FULL
基於文章:
http://blogs.msdn.com/b/mattwar/archive/2007/07/31/linq-building-an-iqueryable-provider-part-ii.aspx https://stackoverflow.com/Converting 2 argument Lambda expression to 1 argument Lambda expression
public static Expression<Func<CDNXL_TwrKarty, bool>> Bind2nd(Expression<Func<CDNXL_TwrKarty, CDNXL_TwrKarty,CDNXL_TwrKarty, bool>> source)
{
Expression newBody = new Rewriter(source.Parameters[0]).Visit(source.Body);
return Expression.Lambda<Func<CDNXL_TwrKarty, bool>>(newBody, source.Parameters[0]);
}
internal class Rewriter : ExpressionVisitor
{
private readonly ParameterExpression candidate_;
public Rewriter(ParameterExpression candidate)
{
candidate_ = candidate;
}
protected override Expression VisitParameter(ParameterExpression p)
{
return candidate_;
}
}
//REPLACE EXECUTING PLACE
var retMultiLamnda = Expression.Lambda<Func<CDNXL_TwrKarty, CDNXL_TwrKarty, CDNXL_TwrKarty, bool>>(body, parametrsNumber, parametrsTyp, parametrsLp);
var retOneLambda = Bind2nd(retMultiLamnda);
var retQuery = query.Where(retOneLambda);
return retQuery;
Thanx Rafal尋求幫助。
+1爲ExprssionVisitor很高興有 – Rafal