1
lstReport=lstReport.Where(o=>DateTime.Parse(o.Field)==DateTime.Parse(o.FieldValue));
//I am creating above statement dynamically like this
var variable = Expression.Variable(typeof(Report));
foreach (SQWFilterConstraint oFC in oFilter.LstFilterConstraint) //using this collection I am making dynamic query
{
Expression ExprLeft =Expression.Property(variable, oFC.Field);
MethodInfo methodDateTimeParse = typeof(DateTime).GetMethod("Parse", newType[] { typeof(string) });
var methodParam = Expression.Parameter(typeof(string), oFC.FieldValue);
Expression exprRight = Expression.Call(methodDateTimeParse, methodParam); //This is working fine for right side
}
var props = new[] { variable };
var lambda = Expression.Lambda<Func<Report, bool>>(ExprPrev, props).Compile();
ReportList = ReportList.Where(lambda).ToList();
所以我需要應用領域上也DateTime.Parse
方法,正值左側(這是下劃線和粗體以上運營商的左側)如何在創建表達式樹時使用DateTime.Parse()方法(即在表達式左側和表達式右側)?
你爲什麼不做同樣的事情你已經做的右側? – svick
我試過,但它不工作,因爲我不提供參數var methodParam = Expression.Parameter(typeof(string),oFC.FieldName); //此函數期望常量值作爲第二個參數而不是fieldname –