Jona and Jeroen,
Why do you think you need to call it though? What's wrong with
String.CompareT o?
I need to generate dynamically sql select statement which compares strings:
SELECT COUNT(*)
FROM Customer
WHERE CustomerId < 'AIRBU';
I expect that
Db.Customers.Wh ere( c =>
Microsoft.Visua lBasic.Compiler Services.Operat ors.CompareStri ng(
c.CustomerId, "AIRBU", false ) < 1 ).Count()
generates correct sql .
I'm not sure that String.CompareT o generates correct statement.
So I created following extension method based on Marc code samples:
public static IQueryable<TLes sThanOrEqual<T> (this IQueryable<T>
source, string property, object value)
{
ParameterExpres sion obj = Expression.Para meter(typeof(T) , "x");
Expression val = Expression.Cons tant(value, typeof(string)) ;
Expression prop = Expression.Prop erty(obj, property);
Expression call = Expression.Call (
typeof(Microsof t.VisualBasic.C ompilerServices .Operators).Get Method("Compare String",
new[] { typeof(string), typeof(string), typeof(bool) }), prop,
val,
Expression.Cons tant(false, typeof(bool)));
BinaryExpressio n testExp = LambdaExpressio n.LessThan(call ,
Expression.Cons tant(1, typeof(int))
);
return source.Where(Ex pression.Lambda <Func<T, bool>>(testExp,
obj));
}
Is this best solution ?
Andrus.