[英]Expression of type 'System.Dynamic.ExpandoObject' cannot be used for parameter of type 'System.Linq.IQueryable`
I am trying to create Expression
for ExpandoObject
and below is my code. 我正在尝试为
ExpandoObject
创建Expression
,下面是我的代码。
var parameter = Expression.Parameter(typeof(KeyValuePair<string, object>), "k");
var left = Expression.Property(parameter, "Key");
var right = Expression.Constant(prop, typeof(string));
var equal = Expression.Equal(left, right);
var whereMethod = typeof(Queryable).GetMethods(BindingFlags.Public | BindingFlags.Static)
.First(_ => _.Name == "Where").MakeGenericMethod(typeof(ExpandoObject));
propExp = Expression.Call(whereMethod, propExp, equal);
And I am getting Exception at Expression.Call
我在
Expression.Call
遇到异常
Expression of type 'System.Dynamic.ExpandoObject' cannot be used for parameter of type 'System.Linq.IQueryable`
类型“ System.Dynamic.ExpandoObject”的表达式不能用于类型“ System.Linq.IQueryable”的参数
Can someone please help? 有人可以帮忙吗?
Rishi 仙人
The expression expects System.Dynamic.ExpandoObject
as the first parameter, just like the exception states: 该表达式期望
System.Dynamic.ExpandoObject
作为第一个参数,就像异常状态一样:
Expression of type 'System.Dynamic.ExpandoObject' cannot be used for parameter of type 'System.Linq.IQueryable`
类型“ System.Dynamic.ExpandoObject”的表达式不能用于类型“ System.Linq.IQueryable”的参数
in this line of code you are trying to convert the where linq to an Expando object: 在此代码行中,您尝试将linq转换为Expando对象:
var whereMethod = typeof(Queryable).GetMethods(BindingFlags.Public | BindingFlags.Static)
.First(_ => _.Name == "Where").MakeGenericMethod(typeof(ExpandoObject));
But you are failing because you have an Iqueryable object: 但是您失败了,因为您有一个Iqueryable对象:
var whereMethod = typeof(Queryable) var whereMethod = typeof(Queryable)
adjust the code so that the whereMethod variable be a dynamic expando object and it will work. 调整代码,使whereMethod变量成为动态的expando对象,它将起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.