How to call Oracle's regexp_like function with Nhibernate QueryOver?

依然范特西╮ 提交于 2019-12-11 12:41:23

问题


I'm aware I need to use Restrictions.Eq and Projections.SqlFunction, but I've been trying for hours without any success (my test app just crashes). Does anyone have an QueryOver example that would do the following in Oracle:

SELECT
  *
FROM
  V_LOG_ENTRIES
WHERE
  regexp_like(ENTRY_TEXT, '(\WPlaced\W)');

UPDATE: Okay, I think part of the problem is that Restrictions.Eq expects an equality, but there is no equality in this case, it's just a function call in the WHERE clause...


回答1:


The syntax should be like this:

// this is inlined string, but could be concatenated from some params
var sql = @" regexp_like(ENTRY_TEXT, '(\WPlaced\W)') " +
           " AS isLike";
var sqlString = new SqlString(sql);

// the ICriterion
var criterion = new NHibernate.Criterion.SQLCriterion(sqlString
    , new string[] {}
    , new IType[] {}
    );

// the query
var query = session.QueryOver<LogEntry>()
    .Where(criterion)
    ...


来源:https://stackoverflow.com/questions/24782474/how-to-call-oracles-regexp-like-function-with-nhibernate-queryover

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!