nHibernate 命名查询不返回所有结果
我有一些简单的命名查询,仅包含连接、蚂蚁耦合子选择。除了一个之外,所有这些都工作正常。问题是,当我在 Management Studio 中运行 SQL 代码时,我得到 177 个结果,而当我使用相同的 SQL 代码运行命名查询时,我得到 20 个结果。我不明白这是为什么。我将命名查询称为所有其他查询:
public IList<InstitutionIndexDTO> GetInstitutionIndexByWorkTimeSearch(int time, int institutionType)
{
IQuery query = GetCurrentSession()
.GetNamedQuery("GetInstitutionsListByTime")
.SetInt32("Type", institutionType)
.SetInt32("TimeUntilClose", time)
.SetResultTransformer(Transformers.AliasToBeanConstructor(typeof(InstitutionIndexDTO).GetConstructors()[0]));
return query.List<InstitutionIndexDTO>();
}
即使我在 SQL 中对参数进行了编码,我仍然得到相同的结果。我尝试使用 Profiler 检查,但生成的 SQL 是完美的,并且在管理工作室中返回所有 177 个结果。InstitutionIndexDTO
工作正常,因为我将它与其他命名查询一起使用。
我有一个有效的命名查询,导致问题的一个是由该查询创建的,添加了额外的 INNER JOIN 并更改了 WHERE 子句。两个查询返回相同的列。
也许有人有一个想法,我可能做错了什么?
I have a few simple named queries with only joins, ant couple subselects. All of them ar working perfectly except one. The problem is, that when i run SQL code in Management Studio, i get 177 results, and when i run named query with the same SQL code, i get 20 results. I can't figure out why is that. I Call named query the as all other:
public IList<InstitutionIndexDTO> GetInstitutionIndexByWorkTimeSearch(int time, int institutionType)
{
IQuery query = GetCurrentSession()
.GetNamedQuery("GetInstitutionsListByTime")
.SetInt32("Type", institutionType)
.SetInt32("TimeUntilClose", time)
.SetResultTransformer(Transformers.AliasToBeanConstructor(typeof(InstitutionIndexDTO).GetConstructors()[0]));
return query.List<InstitutionIndexDTO>();
}
Even when i harcoded parameters in SQL, i still got the same result. I tried checking with Profiler, but generated SQL is perfect and in management studio returns all 177 results.InstitutionIndexDTO
is working correctly, because i use it with other named queries.
I have a working named query, and the one causing problems was made from that one, adding additional INNER JOIN and changing WHERE clause. Both queries returns same columns.
Maybe somebody has an idea, what i could have done wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我测试了我的代码并意识到这一行导致了问题:
(CASE WHEN (DATEPART(dw, GETDATE())) = 1 THEN 7 ELSE (DATEPART(dw, GETDATE()) - 1) END)
如果我理解得很好,问题出在 DATEPART 函数中。有人遇到过这个问题吗?
I tested my code and realised that this line is causing the problem:
(CASE WHEN (DATEPART(dw, GETDATE())) = 1 THEN 7 ELSE (DATEPART(dw, GETDATE()) - 1) END)
If i understand well, the problem is in DATEPART function. Has anybody encountered this problem?