0

我想创建这个 LINQ 查询:

    Result = Result.Where(Function(Row) Convert.ToString(Row(0)).ToUpper = "TEST")

我已经有这个查询:

Result = Result.Where(Function(Row) Convert.ToString(Row(0)) = "TEST")  

使用此代码:

expr = Expression.Call(whereMethod, Result.AsQueryable.Expression,
       Expression.Lambda(Expression.Equal(Expression.Call(convertMethod, Expression.ArrayAccess(rowParameter, Expression.Constant(index))),
       Expression.Constant(constant)), rowParameter))

convertMethod代表Convert.ToString,的index值为 0,且constant值为“TEST”。

现在,我想在这个表达式中添加 ToUpper 方法。

我宣布了这一点:

convertMethod_toupper = GetType(String).GetMethod("ToUpper", New Type() {GetType(Object)})

我发现了这个:表达式调用中的 ToUpper

Convert.ToString(Row(0))我还应该在调用 Expression.Call 之后再调用一次ToUpper 方法。但是怎么做?

谢谢。

编辑:与此同时,我发现这也返回 null:

convertMethod_toupper = GetType(String).GetMethod("ToUpper", New Type() {GetType(Object)})

这有什么问题?

如果这不应该为空,我认为,这应该有效:

expr = Expression.Call(whereMethod, Result.AsQueryable.Expression,
       Expression.Lambda(Expression.Equal(Expression.Call(Expression.Call(convertMethod, Expression.ArrayAccess(rowParameter, Expression.Constant(index))), convertMethod_toupper),
       Expression.Constant(constant)), rowParameter))

EDIT2:我明白了。

convertMethod_toupper = GetType(String).GetMethod("ToUpper", System.Type.EmptyTypes)

并且上面的表达式(在edit1中)有效。

4

0 回答 0