SQLCriterion ArgumentOutOfRangeException

故事扮演 提交于 2019-12-11 10:14:51

问题


What is the correct syntax to create a SQLCriterion?

I have the following code:

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

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

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 

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

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


回答1:


This adjustment should make it:

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


来源:https://stackoverflow.com/questions/26141526/sqlcriterion-argumentoutofrangeexception

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