简体   繁体   English

如何使用Nhibernate QueryOver调用Oracle的regexp_like函数?

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

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). 我知道我需要使用Restrictions.Eq和Projections.SqlFunction,但是我已经尝试了好几个小时都没有成功(我的测试应用程序崩溃了)。 Does anyone have an QueryOver example that would do the following in Oracle: 是否有人有一个QueryOver示例,它将在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... 更新:好的,我认为部分问题是Restrictions.Eq期望相等,但是在这种情况下没有相等,它只是WHERE子句中的函数调用...

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)
    ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM