SQLCriterion ArgumentOutOfRangeException [英] SQLCriterion ArgumentOutOfRangeException

查看:103
本文介绍了SQLCriterion ArgumentOutOfRangeException的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

What is the correct syntax to create a 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);

查询是我的QueryOver实例(使用NHibernateSession创建)

where query is my QueryOver-instance (created with NHibernateSession)

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

When I call query.List() I get the following exception:

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

它被抛出到NHibernate.Criterion.SQLCriterion.ToSqlString(..)

which is thrown somewhere in NHibernate.Criterion.SQLCriterion.ToSqlString(..)

我的SQLCriterion-constructor的语法错误还是我遗漏了其他东西?

Is the syntax of my SQLCriterion-constructor wrong or am I missing something else?

推荐答案

此调整应使其:

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

这篇关于SQLCriterion ArgumentOutOfRangeException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆