var param = Expression.Parameter(typeof(vvTest), “x”);
var member = Expression.Property(param, “field1”);
var body = CompareLessThanOrEqualTo(member, Expression.Constant(“ZZ”));
var exp = Expression.Lambda<Func<vvTest, bool>>(body, param);
If I perform exp, it works. If I use this predicate inside a complex expression it does not work because the parameter is not defined.
Than, I tried compareTo, but OrmLite does not recognize this method.
OrmLite needs the concrete types when constructing the Where expression in order to access the table metadata which is sometimes lost when trying to dynamically construct lambda expressions.
var parameter = Expression.Parameter(typeof(vvTest), “x”);
var member = Expression.Property(parameter, ‘field1’);
var constant = Expression.Constant(value);
var body = Expression.GreaterThan_FOR_ALL_TYPES(member, constant);
var finalExpression = Expression.Lambda<Func<vvTest, bool>>(body, parameter);
It needs to use the > operator or more explicitly a BinaryExpression with the ExpressionType.GreaterThan/ExpressionType.GreaterThanOrEqual/etc node type.
Honestly if you’re constructing expressions dynamically just create SQL string fragments and use the UnsafeWhere(string)/UnsafeAdd/UnsafeOr APIs. You could also construct an entire SQL statement and execute them through db.SqlList<Table>(sql).
Also have you evaluated if using AutoQuery RDBMS is a valid solution?
They include artificial Custom classes that are unintuitive and undiscoverable, i.e. we’d add code bloat to OrmLite that only you would think about consider using. If you can modify it to work with string.Compare() directly we could accept it.
The <> operators are universal you can easily create SQL that will work in each database, e.g. AutoQuery just uses this template to generate its SQL complaint condition:
You can override SqlExpression<T> but each RDBMS has their own SqlExpression classes so you’d need to override it for each you want to support e.g. SqlServerExpression, SqliteExpression, etc.
To get OrmLite to use it you’d also need to override the Dialect Provider to return your custom class, e.g:
public override SqlExpression<T> SqlExpression<T>()
{
return new CustomSqlServerExpression<T>(this);
}