A
Andrus
I tried to create my extension method:
Northwind db = CreateDB();
var q = db.Customers.StartsWith("CompanyName", "a");
but got exception in LambdaExpression.Call() :
No method 'StartsWith' on type 'System.String' is compatible with the
supplied arguments.
Any idea how to fix this ?
Andrus.
static class StartWithExtension {
public static IQueryable<TEntity> StartsWith<TEntity>(this
IQueryable<TEntity> query, string propertyName, string value) {
ParameterExpression param = Expression.Parameter(typeof(TEntity), "p");
MethodCallExpression testExp = LambdaExpression.Call(
Expression.Property(param, propertyName),
"StartsWith",
new Type[] { typeof(string), typeof(System.StringComparison) },
new Expression[] { Expression.Constant(value),
Expression.Constant(System.StringComparison.CurrentCultureIgnoreCase) });
return query.Where(Expression.Lambda<Func<TEntity, bool>>(testExp, param));
}
}
Northwind db = CreateDB();
var q = db.Customers.StartsWith("CompanyName", "a");
but got exception in LambdaExpression.Call() :
No method 'StartsWith' on type 'System.String' is compatible with the
supplied arguments.
Any idea how to fix this ?
Andrus.
static class StartWithExtension {
public static IQueryable<TEntity> StartsWith<TEntity>(this
IQueryable<TEntity> query, string propertyName, string value) {
ParameterExpression param = Expression.Parameter(typeof(TEntity), "p");
MethodCallExpression testExp = LambdaExpression.Call(
Expression.Property(param, propertyName),
"StartsWith",
new Type[] { typeof(string), typeof(System.StringComparison) },
new Expression[] { Expression.Constant(value),
Expression.Constant(System.StringComparison.CurrentCultureIgnoreCase) });
return query.Where(Expression.Lambda<Func<TEntity, bool>>(testExp, param));
}
}