![](/img/trans.png)
[英]Cannot implicitly convert type 'System.Linq.IQueryable<AnonymousType#1>' to 'System.Linq.IQueryable<>'
[英]Expression of type 'System.Dynamic.ExpandoObject' cannot be used for parameter of type 'System.Linq.IQueryable`
我正在嘗試為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);
我在Expression.Call
遇到異常
類型“ System.Dynamic.ExpandoObject”的表達式不能用於類型“ System.Linq.IQueryable”的參數
有人可以幫忙嗎?
仙人
該表達式期望System.Dynamic.ExpandoObject
作為第一個參數,就像異常狀態一樣:
類型“ System.Dynamic.ExpandoObject”的表達式不能用於類型“ System.Linq.IQueryable”的參數
在此代碼行中,您嘗試將linq轉換為Expando對象:
var whereMethod = typeof(Queryable).GetMethods(BindingFlags.Public | BindingFlags.Static)
.First(_ => _.Name == "Where").MakeGenericMethod(typeof(ExpandoObject));
但是您失敗了,因為您有一個Iqueryable對象:
var whereMethod = typeof(Queryable)
調整代碼,使whereMethod變量成為動態的expando對象,它將起作用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.