Reputation: 131
I am trying to create Expression
for ExpandoObject
and below is my code.
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 of type 'System.Dynamic.ExpandoObject' cannot be used for parameter of type 'System.Linq.IQueryable`
Can someone please help?
Rishi
Upvotes: 0
Views: 825
Reputation: 10927
The expression expects System.Dynamic.ExpandoObject
as the first parameter, just like the exception states:
Expression of type 'System.Dynamic.ExpandoObject' cannot be used for parameter of type 'System.Linq.IQueryable`
in this line of code you are trying to convert the where linq to an Expando object:
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:
var whereMethod = typeof(Queryable)
adjust the code so that the whereMethod variable be a dynamic expando object and it will work.
Upvotes: 1