NHibernate Fluent 分组依据
我有这个 nhibernate 标准:
criteria.Add(Subqueries.PropertyIn("Id", DetachedCriteria.For<ReconItemReconSide>()
.SetProjection(Projections.ProjectionList()
.Add(Projections.GroupProperty("ReconItemFk"))
.Add(Projections.Min("ReconciliationSideFk")))
.Add(Expression.In(Projections.Property("ReconItemFk"), items))
));
- 这成为这个查询(我已经从外部选择中删除了一些字段以最小化此处的长度):
SELECT this_.Id as Id8_0_
FROM CI.BM_RECONCILIATION_SIDE this_
WHERE this_.Id in (SELECT this_0_.BM_RECON_ITEM as y0_,
min(this_0_.BM_RECONCILIATION_SIDE) as y1_
FROM CI.BM_RECON_ITEM_RECON_SIDE this_0_
WHERE this_0_.BM_RECON_ITEM in (345061 /* :p0 */,345877 /* :p1 */)
GROUP BY this_0_.BM_RECON_ITEM)
问题是我希望内部选择仅选择一个字段(min(this_0_. BM_RECONCILIATION_SIDE)),但 groupby 还会将 groupby-field 添加到选择中。
我希望能够创建一个 groupby 而不必投影 groupby 字段本身。 查询应该类似于:
SELECT this_.Id as Id8_0_
FROM CI.BM_RECONCILIATION_SIDE this_
WHERE this_.Id in (SELECT
min(this_0_.BM_RECONCILIATION_SIDE) as y1_
FROM CI.BM_RECON_ITEM_RECON_SIDE this_0_
WHERE this_0_.BM_RECON_ITEM in (345061 /* :p0 */,345877 /* :p1 */)
GROUP BY this_0_.BM_RECON_ITEM)
知道如何解决这个问题吗?
I have this nhibernate criteria:
criteria.Add(Subqueries.PropertyIn("Id", DetachedCriteria.For<ReconItemReconSide>()
.SetProjection(Projections.ProjectionList()
.Add(Projections.GroupProperty("ReconItemFk"))
.Add(Projections.Min("ReconciliationSideFk")))
.Add(Expression.In(Projections.Property("ReconItemFk"), items))
));
-which becomes this query (I have removed some of the fields from the outer select to minimize the length here):
SELECT this_.Id as Id8_0_
FROM CI.BM_RECONCILIATION_SIDE this_
WHERE this_.Id in (SELECT this_0_.BM_RECON_ITEM as y0_,
min(this_0_.BM_RECONCILIATION_SIDE) as y1_
FROM CI.BM_RECON_ITEM_RECON_SIDE this_0_
WHERE this_0_.BM_RECON_ITEM in (345061 /* :p0 */,345877 /* :p1 */)
GROUP BY this_0_.BM_RECON_ITEM)
The problem is that I want the inner-select to select one field only (min(this_0_.BM_RECONCILIATION_SIDE)), but the groupby also add the groupby-field to the select.
I want to be able to create a groupby without having to project the groupby field itself.
The query should look similar to this:
SELECT this_.Id as Id8_0_
FROM CI.BM_RECONCILIATION_SIDE this_
WHERE this_.Id in (SELECT
min(this_0_.BM_RECONCILIATION_SIDE) as y1_
FROM CI.BM_RECON_ITEM_RECON_SIDE this_0_
WHERE this_0_.BM_RECON_ITEM in (345061 /* :p0 */,345877 /* :p1 */)
GROUP BY this_0_.BM_RECON_ITEM)
Any idea how to solve this ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,这似乎仍然是 nHib 的未决问题。
就像他们总是说的那样 - 欢迎您自己实现它..:)
well, it seems like this is still an open issue with nHib.
like they always say- you're welcome to implement it yourself.. :)