Entity framework 使用.expand.orderby.take时可能存在Breeze/EntityFramework错误

Entity framework 使用.expand.orderby.take时可能存在Breeze/EntityFramework错误,entity-framework,breeze,Entity Framework,Breeze,在工作中处理项目时发现此问题,但已使用Breeze的DocCode示例成功复制了此问题。我正在使用最新的1.3.0。使用“expand”、“orderby”和“take”时,查询返回的记录基本上是错误的。这个问题可以通过queryTests.js中的“按相关类别降序排序的产品”测试来证明: 测试中的查询是: var query = EntityQuery.from("Products") .expand("Category") .orderBy("Cate

在工作中处理项目时发现此问题,但已使用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订购的,这会导致返回错误的记录


这是一个bug还是我做错了什么?

编辑:从v1.3.2开始,这应该得到修复。如果你仍然看到问题,请发回这里



好的,我刚刚重新编程,这是一个bug。感谢您的发现和报告。我将在下一版本中尝试进行修复。当它进来时,我会发回这里

谢谢Jay,我应该可以在下周的某个时候测试更新。我正在使用v1.4,并且仍然在类似的场景中看到这种行为。我知道这是一个非常古老的线程—希望有人仍然看到您是在运行上面显示的查询还是其他什么?我正在运行其他东西—如果orderBy列是expand子句中项的属性,则问题似乎会发生。如果我在基本查询中按某个对象排序,它似乎工作正常。orderBy的“有效”和“无效”之间唯一的区别是,我注意到其中一个不起作用的是一个整数列。顺便说一句,我使用的是Breeze客户端v1.4.8