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

RowNumberForPaging, two tables and columns with same name #5641

Closed
sepplK opened this issue Jun 3, 2016 · 7 comments
Closed

RowNumberForPaging, two tables and columns with same name #5641

sepplK opened this issue Jun 3, 2016 · 7 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@sepplK
Copy link

sepplK commented Jun 3, 2016

Steps to reproduce

optionsBuilder.UseSqlServer("connectionString", o=>
{
    o.UseRowNumberForPaging();
});

var orders = (from ba in dc.BestellungenArtikel
                join b in dc.Bestellungen on ba.Bestellung equals b.Id
                orderby b.Eingang descending
                select new
                {
                    OrderId = b.Id,
                    ArtId = ba.Id,
                    ArtName = ba.Name
                }).Skip(10).Take(20).ToList();
IDs equal:
{ OrderId = 387945, ArtId = 387945, ArtName = Guten Morgen } 
{ OrderId = 387944, ArtId = 387944, ArtName = Romantisches Duett }
exec sp_executesql N'SELECT [t].[ID], [t].[ID] AS [c0], [t].[name]
FROM (
    SELECT [b].[ID], [ba].[ID] AS [c0], [ba].[name], ROW_NUMBER() OVER(ORDER BY [b].[eingang] DESC) AS [__RowNumber__]
    FROM [bestellungen_artikel] AS [ba]
    INNER JOIN [bestellungen] AS [b] ON [ba].[bestellung] = [b].[ID]
) AS [t]
WHERE ([t].[__RowNumber__] > @__p_0) AND ([t].[__RowNumber__] <= (@__p_0 + @__p_1))',N'@__p_0 int,@__p_1 int',@__p_0=10,@__p_1=20

Without Paging:

var orders = (from ba in dc.BestellungenArtikel
                join b in dc.Bestellungen on ba.Bestellung equals b.Id
                orderby b.Eingang descending
                where b.Id == 387945 || b.Id == 387944
                select new
                {
                    OrderId = b.Id,
                    ArtId = ba.Id,
                    ArtName = ba.Name
                }).ToList();
IDs OK:
{ OrderId = 387945, ArtId = 758860, ArtName = Guten Morgen }
{ OrderId = 387944, ArtId = 758859, ArtName = Romantisches Duett }
SELECT [b].[ID], [ba].[ID], [ba].[name]
FROM [bestellungen_artikel] AS [ba]
INNER JOIN [bestellungen] AS [b] ON [ba].[bestellung] = [b].[ID]
WHERE [b].[ID] IN (387945, 387944)
ORDER BY [b].[eingang] DESC

The issue

OrderId and ArtId is the same after using RowNumberPaging.
Select in paged query: [t].[ID], [t].[ID] AS [c0], [t].[name] VS [b].[ID], [ba].[ID], [ba].[name]

Further technical details

EF Core version: RC2
SQL version: 2008 R2

@maumar
Copy link
Contributor

maumar commented Jun 3, 2016

Most likely duplicate of #4739

@sepplK
Copy link
Author

sepplK commented Jun 3, 2016

@divega
Copy link
Contributor

divega commented Jun 3, 2016

Not sure if it is the same as #4739. That one produces a NullReferenceException. This one returns wrong data from the query.

@divega
Copy link
Contributor

divega commented Jun 3, 2016

@maumar explained to me that although the symptoms are different it looks like another manifestation the same underlying issue as #4739.

@smitpatel
Copy link
Contributor

smitpatel commented Jun 3, 2016

Both have same cause. The projections are incorrectly renamed while translating for row number paging. In this case it doesn't throw exception because the property which gets wrong value is same type is the other property . So incorrect result. It throws NRE in #4739 because null value is being assigned to non-null property.

@maumar
Copy link
Contributor

maumar commented Jun 6, 2016

fixed in 11c18e6

@maumar maumar closed this as completed Jun 6, 2016
@ajcvickers
Copy link
Contributor

@sepplK If you are still using RowNumberForPaging, could you please comment on issue #13959 and let us know why?

@ajcvickers ajcvickers added closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-unknown type-bug and removed type-unknown labels Oct 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

5 participants