question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Row_Number is always 1 when selected after first query

See original GitHub issue

In the below query, when i to a ToList() after first select i am getting correct row index with each record, but when i try to get the result based on where filter i am always getting 1 in return value.

await repository.Query().OrderBy(t => t.DateCreated)
                    .Where(pb => pb.IsActive == true && pb.SiteId == currentBlogPost.SiteId && pb.BlogPostTypeId == currentBlogPost.BlogPostTypeId)  
                    .Select(x => new BlogMinimalInfo { Index = Sql.Ext.RowNumber().Over().OrderBy(x.DateCreated).ToValue(),Id=x.Id })
                    .ToLinqToDB()
                    .Where(pb => pb.Id == currentBlogPost.Id)
                    .Select(pb => pb.Index) ==> this always comes 1 but should be different based on each Id
                    .FirstOrDefaultAsyncLinqToDB();

i need this query to work so i can select prev & next record of current row which is guid Ids. And Enumeration will be bad once database starts growng.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
sdanylivcommented, Dec 31, 2021

Yes it is a bug. Try to put AsSubQuery() exactly before ToLinqToDB()

0reactions
aloksharma1commented, Jan 4, 2022

@sdanyliv can you look into this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

row number always return 1 for each row in sql server
The above query always returns rownumber 1 for each row. When I use the select statement outside, its problem. Otherwise if I remove...
Read more >
Overview of the SQL ROW_NUMBER function
ROW_NUMBER adds a unique incrementing number to the results grid. The order, in which the row numbers are applied, is determined by the...
Read more >
Is SELECT ROW_NUMBER() guaranteed to return results ...
I was expecting the row number to be assigned to the rows but I was not expecting the rows to come back sorted...
Read more >
Rownum - Ask TOM - Oracle
1. I have a table called a where I have more than one row. When I put a query "SELECT * FROM A...
Read more >
ROW_NUMBER (Transact-SQL) - SQL Server
ROW_NUMBER is a temporary value calculated when the query is run. To persist numbers in a table, see IDENTITY Property and SEQUENCE. Transact- ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found