0
時可能發生微風/ EntityFramework錯誤在工作中處理項目時發現了此問題,但已使用Breeze的DocCode樣本設法複製該問題。我正在使用最新的1.3.0。基本上,在使用'expand','orderby'和'take'時,查詢會返回錯誤的記錄。這個問題可以用「由相關類別分類產品降」測試中queryTests.js證明:當使用.expand .orderby .take
查詢測試是:
var query = EntityQuery.from("Products")
.expand("Category")
.orderBy("Category.CategoryName desc, ProductName");
這會導致下面的SQL將發行到SQL Server :
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導致返回錯誤的記錄。
所以這是一個錯誤還是我做錯了什麼?
謝謝Jay,我應該能夠在下週的某個時候測試更新。 – 2013-05-02 09:44:37
我正在使用v1.4,並且仍然在類似的情況下看到此行爲。我知道這是一個非常舊的主題 - 希望有人仍然看到它 – Nick 2014-12-08 22:20:29
您是否正在運行上面顯示的查詢或其他內容? – 2014-12-09 00:15:15