How should I go about writing a backwards like statement using NHibernate criteria?
WHERE 'somestring' LIKE [Property] + '%'
Sub Question:
Can you access the abstract root alias in a SQLCriterion expression?
This is somewhat achievable using the SQLCriterion expression
Expression.Sql("? like {alias}.[Property] + '.%'", value, NHibernateUtil.String);
However, in the case of class inheritance, {alias}
is replaced with the incorrect alias for the column.
Example (these classes are stored in separate tables):
public abstract class Parent
{
public virtual string Property { get; set; }
}
public class Child : Parent { }
The above query executed with Child
as the root type will replace {alias}
with the alias to the Child
table rather than the Parent
table. This results in an invalid column exception.
I need to execute a like statement as above where the property exists on the parent table rather than on the root type table.