开发者

Reverse Expression.Like criterion

开发者 https://www.devze.com 2023-01-01 12:03 出处:网络
How should I go about writing a backwards like statement using NHibernate criteria? WHERE \'somestring\' LIKE [Property] + \'%\'

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 expres开发者_StackOverflow社区sion

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.


Have you tried adding the NOT (!) in front of the operator for the one you want but don't want. i think it might work.

0

精彩评论

暂无评论...
验证码 换一张
取 消