简体   繁体   English

类型“ System.Dynamic.ExpandoObject”的表达式不能用于类型“ System.Linq.IQueryable”的参数

[英]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.

相关问题 无法隐式转换类型&#39;System.Linq.IQueryable <AnonymousType#1> &#39;到&#39;System.Linq.IQueryable &lt;&gt;&#39; - Cannot implicitly convert type 'System.Linq.IQueryable<AnonymousType#1>' to 'System.Linq.IQueryable<>' 无法转换类型&#39;System.Linq.IQueryable <double?> &#39; 漂浮&#39; - Cannot convert type 'System.Linq.IQueryable<double?>' to 'float' 无法隐式转换System.Linq.IQueryable类型 <string> 串起来 - Cannot implicitly convert type System.Linq.IQueryable<string> to string 无法隐式转换类型&#39;System.Linq.IQueryable? - Cannot implicitly convert type 'System.Linq.IQueryable? MVC 5无法将类型&#39;System.Linq.IQueryable隐式转换为bool吗? - MVC 5 Cannot implicitly convert type 'System.Linq.IQueryable to bool? 无法隐式转换类型'System.Linq.IQueryable <AnonymousType#1>' - Cannot implicitly convert type 'System.Linq.IQueryable<AnonymousType#1>' 无法将类型'System.Linq.IQueryable <int>'隐式转换为'int?' - Cannot implicitly convert type 'System.Linq.IQueryable<int>' to 'int?' 无法隐式转换类型&#39;System.Linq.IQueryable <double> &#39;到&#39;加倍&#39; - Cannot implicitly convert type 'System.Linq.IQueryable<double>' to 'double' 无法隐式转换类型&#39;System.Linq.IQueryable - Cannot implicitly convert type 'System.Linq.IQueryable 无法在内部联接上隐式转换类型system.linq.iqueryable - cannot implicitly convert type system.linq.iqueryable on inner join
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM