我正在使用NHibernate 3.3.1.4000
和FluentNHibernate 1.3.0.733
使用SQL Server 2012
,我需要将查询重写为 IQueryOver 以在服务器端进行此计算,而无需调用存储过程。
WITH CTE_Links AS
(
SELECT Article1, MIN(Article2) Article2
FROM dbo.LinkBetweenArticles
GROUP BY Article1
HAVING Article1 > MIN(Article2)
)
SELECT COUNT(*)
FROM dbo.ArticlePlacedBySeller a
LEFT JOIN CTE_Links l ON a.Id = l.Article1
WHERE l.Article2 IS NULL
AND ConfirmedPosition_Id = 1000
如果需要,可以在此处阅读脚本说明