Hi there,
I have this extension method.
public static IQueryable<T> SearchBy<T>(this IQueryable<T> source, SearchCriteria criteria)
{
//throw an error if the source is null
if (source == null)
{
throw new ArgumentNullException("source");
}
ParameterExpression parameter = Expression.Parameter(source.ElementType, string.Empty);
var property = Expression.Equal(Expression.PropertyOrField(parameter, criteria.Property), Expression.Constant(criteria.PropertyValue));
LambdaExpression lambda = Expression.Lambda(property, parameter);
Expression methodCallExpression = Expression.Call(typeof(Queryable), "SelectMany",
new Type[] { source.ElementType, property.Type },
source.Expression, Expression.Quote(lambda));
return source.Provider.CreateQuery<T>(methodCallExpression);
}
I get this error
No method 'SelectMany' on type 'System.Linq.Queryable' is compatible with the supplied arguments.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: No method 'SelectMany' on type 'System.Linq.Queryable' is compatible with the supplied arguments.
Source Error:
Line 67: LambdaExpression lambda = Expression.Lambda(property, parameter);
Line 68:
Line 69: Expression methodCallExpression = Expression.Call(typeof(Queryable), "SelectMany",
Line 70: new Type[] { source.ElementType, property.Type },
Line 71: source.Expression, Expression.Quote(lambda));
when I call this method from the entity framework like this
this.grdReservations.DataSource = dataContext.CustomerSet.SearchBy(crit);
this is SearchCriteria
SearchCriteria crit = new SearchCriteria();
crit.Property = "UserName";
crit.PropertyValue = "new_user";
crit.Search = SearchType.Equal;
If anyone could take a look and give me a push in the right direction I'd be very happy.
Thanks for your time.
Edit: I'm home so I can't test but any method I try ("Select", "Where", "SelectMany") have all returned this error, so I'm assuming I'm doing something else wrong.