I am trying to build contains expression.
private Expression<Func<T, bool>> Contains<T>(string property, IEnumerable<dynamic> values, T item)
{
ParameterExpression pe = Expression.Parameter(item.GetType(), "c");
Expression columnNameProperty = Expression.Property(pe, property);
var someValueContain = Expression.Constant(values, values.GetType());
var convertExpression = Expression.Convert(columnNameProperty, typeof(Guid));
Expression expression = Expression.Call(someValueContain, "Contains", new Type[] { }, convertExpression);
return Expression.Lambda<Func<T, bool>>(expression, pe);
}
at run time I got this exception.
"No method 'Contains' exists on type 'System.Data.Linq.DataQuery`1[System.Object]'."
the soultion was to cast values parameter to list
private Expression<Func<T, bool>> Contains<T>(string property, IEnumerable<dynamic> values, T item)
{
ParameterExpression pe = Expression.Parameter(item.GetType(), "c");
Expression columnNameProperty = Expression.Property(pe, property);
Guidvalues = values.Cast<Guid>().ToList();
var someValueContain = Expression.Constant(Guidvalues, Guidvalues.GetType());
var convertExpression = Expression.Convert(columnNameProperty, typeof(Guid));
Expression expression = Expression.Call(someValueContain, "Contains", new Type[] { }, convertExpression);
return Expression.Lambda<Func<T, bool>>(expression, pe);
}
the problem that the values list is more that 10000 so the performance was low and I got this exception
"The incoming request has too many parameters. The server supports a maximum of 2100 parameters. Reduce the number of parameters and resend the request."
I there any way to build dynamically lambda expression that generate like this query
select * from x where id in (select id from y)
System.Linq.Queryable.valuesDataQuery<object>? Where did you lose the concrete type?