在Criteria Restrictions.In中使用来自sproc的结果

时间:2012-08-13 18:13:25

标签: nhibernate criteria detachedcriteria

我有这个独立的标准:

DetachedCriteria students = DetachedCriteria.For(typeof(Submission)) 
.SetProjection(Projections.Property("ID"))
.Add(Restrictions.In("JicsStudent.HostID", visiblestudents));

visiblestudents是List<string>。它运行良好,直到我遇到2100参数限制。 visiblestudents由另一个查询填充,该查询在sproc中有一些疯狂的业务逻辑。然后从sproc返回到linq过滤到list<string>

所以我的问题是有没有办法用sproc替换list<string>来防止SQL错误?到目前为止我在stackoverflow上找到的所有内容都表明我应该使用列表创建一个临时表,然后使用连接,但我的主管更喜欢我没有使用临时表。

1 个答案:

答案 0 :(得分:0)

我们找到了一个似乎按照我们想要的方式运行的解决方案;

var n = new object[2];
var o = new IType[2];

DetachedCriteria students = DetachedCriteria.For(typeof (Submission))
.SetProjection(Projections.Property("ID"))
.Add(Expression.Sql("{alias}.StudentUserID in (select UserId from RMS_udfVisibleStudents(?, ?))", n, o));
相关问题