You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not really sure where is the bug. It looks like if it jumps over the OrderDetails propety and queries the data base directly.
Looking at the generated SQL its clear. It generates:
SELECT [t0].[OrderID], [t0].[c0]
FROM (
SELECT [t1].[OrderID], (
SELECT COUNT(*)
FROM [dbo].[Order Details] AS t2
) AS c0
FROM [dbo].[Orders] AS t1
) AS t0
WHERE ([t0].[OrderID] = 10537)
Instead of:
SELECT [t0].[OrderID], [t0].[c0]
FROM (
SELECT [t1].[OrderID], (
SELECT COUNT(*)
FROM [dbo].[Order Details] AS t2
WHERE t2.OrderID = [t1].[OrderID] -- only rows belong to this order
) AS c0
FROM [dbo].[Orders] AS t1
) AS t0
WHERE ([t0].[OrderID] = 10537)
Here is a failing Test:
[Fact]
public void Sub_Elements() {
var countAfterRetrieving = _db.Orders.Where(o => o.OrderID == 10537).Single().OrderDetails.Count();
var countBeforeRetrieving = _db.Orders
.Select(o => new {o.OrderID, Count = o.OrderDetails.Count()})
.Where(o => o.OrderID == 10537)
.Single()
.Count;
}
countBeforeRetrieving is usually the count of ALL OrderDetails
The text was updated successfully, but these errors were encountered: