在处理工作项目时发现了这个问题,但是设法使用Breeze的DocCode示例复制了它。我使用的是最新的1.3.0。基本上,当使用'expand','orderby'和'take'时,查询返回错误的记录。可以通过queryTests.js中的“按相关类别降序排序”测试来证明此问题:
测试中的查询是:
var query = EntityQuery.from("Products")
.expand("Category")
.orderBy("Category.CategoryName desc, ProductName");
这会导致向SQL Server发出以下SQL:
SELECT
[Extent1].[ProductID] AS [ProductID],
[Extent1].[ProductName] AS [ProductName],
[Extent1].[SupplierID] AS [SupplierID],
[Extent1].[CategoryID] AS [CategoryID],
[Extent1].[QuantityPerUnit] AS [QuantityPerUnit],
[Extent1].[UnitPrice] AS [UnitPrice],
[Extent1].[UnitsInStock] AS [UnitsInStock],
[Extent1].[UnitsOnOrder] AS [UnitsOnOrder],
[Extent1].[ReorderLevel] AS [ReorderLevel],
[Extent1].[Discontinued] AS [Discontinued],
[Extent2].[CategoryID] AS [CategoryID1],
[Extent2].[CategoryName] AS [CategoryName],
[Extent2].[Description] AS [Description],
[Extent2].[Picture] AS [Picture]
FROM [dbo].[Products] AS [Extent1]
LEFT OUTER JOIN [dbo].[Categories] AS [Extent2] ON [Extent1].[CategoryID] = [Extent2].[CategoryID]
ORDER BY [Extent2].[CategoryName] DESC, [Extent1].[ProductName] ASC
哪个很好,并给出按CategoryName排序的正确结果。但是,如果我将查询更改为以下内容:
var query = EntityQuery.from("Products")
.expand("Category")
.orderBy("Category.CategoryName desc, ProductName").take(10);
我添加了'.take(10)'。 SQL变为:
exec sp_executesql N'SELECT
[Limit1].[ProductID] AS [ProductID],
[Limit1].[ProductName] AS [ProductName],
[Limit1].[SupplierID] AS [SupplierID],
[Limit1].[CategoryID1] AS [CategoryID],
[Limit1].[QuantityPerUnit] AS [QuantityPerUnit],
[Limit1].[UnitPrice] AS [UnitPrice],
[Limit1].[UnitsInStock] AS [UnitsInStock],
[Limit1].[UnitsOnOrder] AS [UnitsOnOrder],
[Limit1].[ReorderLevel] AS [ReorderLevel],
[Limit1].[Discontinued] AS [Discontinued],
[Extent3].[CategoryID] AS [CategoryID1],
[Extent3].[CategoryName] AS [CategoryName],
[Extent3].[Description] AS [Description],
[Extent3].[Picture] AS [Picture]
FROM (SELECT TOP (@p__linq__0) [Extent1].[ProductID] AS [ProductID], [Extent1].[ProductName] AS [ProductName]\, [Extent1].[SupplierID] AS [SupplierID], [Extent1].[CategoryID] AS [CategoryID1], [Extent1].[QuantityPerUnit] AS [QuantityPerUnit], [Extent1].[UnitPrice] AS [UnitPrice], [Extent1].[UnitsInStock] AS [UnitsInStock], [Extent1].[UnitsOnOrder] AS [UnitsOnOrder], [Extent1].[ReorderLevel] AS [ReorderLevel], [Extent1].[Discontinued] AS [Discontinued], [Extent2].[CategoryName] AS [CategoryName]
FROM [dbo].[Products] AS [Extent1]
LEFT OUTER JOIN [dbo].[Categories] AS [Extent2] ON [Extent1].[CategoryID] = [Extent2].[CategoryID]
ORDER BY [Extent1].[ProductID] ASC ) AS [Limit1]
LEFT OUTER JOIN [dbo].[Categories] AS [Extent3] ON [Limit1].[CategoryID1] = [Extent3].[CategoryID]
ORDER BY [Limit1].[CategoryName] DESC, [Limit1].[ProductName] ASC',N'@p__linq__0 int',@p__linq__0=10
哪个错误是因为Extent1按ProductID而不是CategoryName排序,导致返回错误的记录。
这是一个错误还是我做错了什么?
答案 0 :(得分:0)
编辑:从v 1.3.2开始,这应该是固定的。如果您仍然看到问题,请回复此处。
好的,我刚刚重新编写它,这是一个错误。感谢您查找并报告。我将尝试在下一个版本中修复。当它进入时我会回到这里。