Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sub elements are not retrieved correctly inside a query #2

Open
mouk opened this issue Jul 8, 2009 · 2 comments
Open

Sub elements are not retrieved correctly inside a query #2

mouk opened this issue Jul 8, 2009 · 2 comments

Comments

@mouk
Copy link

mouk commented Jul 8, 2009

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;

    Assert.Equal(countAfterRetrieving, countBeforRetrieving);

}

countBeforeRetrieving is usually the count of ALL OrderDetails

@mouk
Copy link
Author

mouk commented Jul 8, 2009

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)

I just don't know where to fix this :-)

@robconery
Copy link
Collaborator

Neither do I :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants