How do I need to write the opposite statement using NHibernate criteria?
WHERE 'somestring' LIKE [Property] + '%'
Question:
Is it possible to access an abstract root alias in an SQLCriterion expression?
This can be achieved using the SQLCriterion expression.
Expression.Sql("? like {alias}.[Property] + '.%'", value, NHibernateUtil.String);
However, in the case of class inheritance, it {alias}is replaced with the wrong 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 with Childas the root type will replace the {alias}alias with the table Child, not the table Parent. This results in an invalid column exception.
I need to execute a similar statement, as indicated above, where the property exists in the parent table, and not in the root type table.