我只是想知道其他人遇到这个问题。 使用Group By或时,SubSonic生成不正确的SQL 与分页不同。这是已知的错误吗?
注意使用分页时,group by是在错误的位置。
没有分页的SubSonic SQL输出:
exec sp_executesql N'SELECT [dbo].[vwMapProject].[Id], [dbo].[vwMapProject].[Name]
FROM [dbo].[vwMapProject]
INNER JOIN [dbo].[Product_ProductComponent] ON [dbo].[vwMapProject].[ProductId] = [dbo].[Product_ProductComponent].[ProductId]
INNER JOIN [dbo].[ProductComponent] ON [dbo].[Product_ProductComponent].[ProductComponentId] = [dbo].[ProductComponent].[Id]
WHERE [dbo].[ProductComponent].[ExternalId] LIKE @ExternalId0
GROUP BY [dbo].[vwMapProject].[Id], [dbo].[vwMapProject].[Name]
',N'@ExternalId0 nvarchar(8)',@ExternalId0=N'GC767AV%'
使用分页的SubSonic SQL输出:
exec sp_executesql N'
SELECT *
FROM (SELECT ROW_NUMBER() OVER ( ORDER BY Id) AS Row,
[dbo].[vwMapProject].[Id], [dbo].[vwMapProject].[Name]
FROM [dbo].[vwMapProject]
INNER JOIN [dbo].[Product_ProductComponent] ON [dbo].[vwMapProject].[ProductId] = [dbo].[Product_ProductComponent].[ProductId]
INNER JOIN [dbo].[ProductComponent] ON [dbo].[Product_ProductComponent].[ProductComponentId] = [dbo].[ProductComponent].[Id]
GROUP BY [dbo].[vwMapProject].[Id], [dbo].[vwMapProject].[Name]
WHERE [dbo].[ProductComponent].[ExternalId] LIKE @ExternalId0
) AS PagedResults
WHERE Row >= 1 AND Row <= 20',N'@ExternalId0 nvarchar(8)',@ExternalId0=N'GC767AV%'
答案 0 :(得分:2)
这应该在当前版本中修复 - 3.0.0.3。如果你没有它 - 请前往我们的项目网站,因为这是一个早期报告的错误,我花了一些时间试图指出它:)