Andrus,
Well, the error is pretty explicit. You are trying to call the static
StartsWith method on the LambdaExpression class. However, that method
doesn't exist.

Signature
- Nicholas Paldino [.NET/C# MVP]
- mvp@spam.guard.caspershouse.com
>I tried to create StartsWith extension method for Mark
>DynamicQueryExtension
[quoted text clipped - 40 lines]
> return query.Where(Expression.Lambda<Func<TEntity,bool>>(testExp, param));
> }
Andrus - 23 Jan 2008 13:39 GMT
Nicholas,
> Well, the error is pretty explicit. You are trying to call the static
> StartsWith method on the LambdaExpression class. However, that method
> doesn't exist.
Thank you.
Do you have any idea how to fix this code?
I want Dynamic Linq to force generation of parameterized query
ExecuteCommand( "select * FROM Products WHERE %0 ILIKE %1 || '%' ",
columnName, startOfValue );
In this case server uses index if this exists.
Andrus.
Andrus - 23 Jan 2008 18:24 GMT
> Well, the error is pretty explicit. You are trying to call the static
> StartsWith method on the LambdaExpression class. However, that method
> doesn't exist.
I think I need to create expression
p.&propertyName.StartsWith(&value,
System.StringComparison.CurrentCultureIgnoreCase)
I tried the code below got got runtime error
No method 'StartsWith' on type 'System.String' is compatible with the
supplied arguments.
StartsWith( string, System.StringComparison ) method exists in .NET
How to fix this error ?
public static IQueryable<TEntity> StartsWith<TEntity>(this
IQueryable<TEntity> query, string propertyName, string value) {
ParameterExpression param = Expression.Parameter(typeof(TEntity), "p");
//Error: No method 'StartsWith' on type 'System.String' is compatible with
the supplied arguments.
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));
}