例如:x => x.Name =“g”
我有这样的代码块
public Expression<Func<TEntity,bool>> SearchExpression() { var c = new ConstantExpression[_paramList.Count]; var b = new BinaryExpression[_paramList.Count]; BinaryExpression comparisonExpression = null; var entity = Expression.Parameter(typeof(TEntity)); for (int i = 0; i < _paramList.Count; i++) { var value = Convert.ChangeType(_paramList[i].Item2 /*"g"*/,_paramList[i].Item3 /*System.String*/); c[i] = Expression.Constant(value); //"g" // PROBLEM IS HERE b[i] = Expression.Equal(Expression.Property(entity,_paramList[i].Item1 /*Name*/,c[i]); // PROBLEM IS HERE } _paramList.Clear(); comparisonExpression = b.Aggregate(Expression.And); return Expression.Lambda<Func<TEntity,bool>>(comparisonExpression,entity); }
像魅力一样工作,但我需要Expression.Like(喜欢“g”不等于“g”)
Expression.Like(Expression.Property(entity,_paramList[i].Item1),c[i])
更新:
我写了这样的东西:
Expression.Call(Expression.Property(entity,typeof(String).GetMethod("Contains"),new Expression[] { c[i] });
但我需要BinaryExpression而不是MethodCallExpression