SQLCriterion ArgumentOutOfRangeException

时间:2014-10-01 12:36:17

标签: c# .net nhibernate queryover

创建SQLCriterion的正确语法是什么?

我有以下代码:

var sqlCriterion = new SQLCriterion(
                new SqlString("{alias}.Id IN (SELECT Id FROM dbo.fGetSomeIds(?1, ?2))"),
                new object[] { "param1", "param2" },
                new IType[] { NHibernateUtil.String, NHibernateUtil.String });

query.Where(sqlCriterion);

其中query是我的QueryOver实例(使用NHibernateSession创建)

当我调用query.List()时,我得到以下异常:

Index was out of range. Must be non-negative and less than the size of the collection parameter name:index 

在NHibernate.Criterion.SQLCriterion.ToSqlString(..)

中抛出

我的SQLCriterion构造函数的语法是错误的还是我错过了其他什么?

1 个答案:

答案 0 :(得分:4)

这种调整应该是:

var criterion = NHibernate.Criterion.Expression
    .Sql("({alias}.Id IN (SELECT Id FROM dbo.fGetSomeIds(?, ?))"
        + " AS MyCriteria",
        new object[] { "param1", "param2" },
        new IType[] { NHibernateUtil.String, NHibernateUtil.String });

// query.Where(sqlCriterion);
query.Where(criterion);