Windowed functions don't work? * is server-side method.
See original GitHub issueI’m getting an error 'RowNumber' is server-side method.
Can’t find a window function test for anything with an Over
clause When I created one it broke.
was changed to test the window function:
var q = ctx.Issue73Entities
.Where(x => x.Name == "Name1_3")
- .Select(x => x.Parent!.Name + ">" + x.Name);
+ .Select(x => Sql.Ext.RowNumber().Over().OrderBy(x.Name).ToValue());
var efItems = q.ToList();
var linq2dbItems = q.ToLinqToDB().ToList();
I wonder if there should be an options turned on or something similar to this code usually found in DbContext.OnConfiguring(DbContextOptionsBuilder optionsBuilder)
method:
.UseSqlServer("conn-string", options => options.AddRowNumberSupport());
Here is the full stack trace:
System.InvalidOperationException
HResult=0x80131509
Message=An exception was thrown while attempting to evaluate a LINQ query parameter expression. See the inner exception for more information. To show additional information call 'DbContextOptionsBuilder.EnableSensitiveDataLogging'.
Source=Microsoft.EntityFrameworkCore
StackTrace:
at Microsoft.EntityFrameworkCore.Query.Internal.ParameterExtractingExpressionVisitor.GetValue(Expression expression, String& parameterName)
at Microsoft.EntityFrameworkCore.Query.Internal.ParameterExtractingExpressionVisitor.Evaluate(Expression expression, Boolean generateParameter)
at Microsoft.EntityFrameworkCore.Query.Internal.ParameterExtractingExpressionVisitor.Visit(Expression expression)
at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.Internal.ParameterExtractingExpressionVisitor.Visit(Expression expression)
at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.Internal.ParameterExtractingExpressionVisitor.Visit(Expression expression)
at System.Linq.Expressions.ExpressionVisitor.VisitLambda[T](Expression`1 node)
at System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.Internal.ParameterExtractingExpressionVisitor.Visit(Expression expression)
at System.Linq.Expressions.ExpressionVisitor.VisitUnary(UnaryExpression node)
at System.Linq.Expressions.UnaryExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.Internal.ParameterExtractingExpressionVisitor.Visit(Expression expression)
at System.Dynamic.Utils.ExpressionVisitorUtils.VisitArguments(ExpressionVisitor visitor, IArgumentProvider nodes)
at System.Linq.Expressions.ExpressionVisitor.VisitMethodCall(MethodCallExpression node)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.Internal.ParameterExtractingExpressionVisitor.Visit(Expression expression)
at Microsoft.EntityFrameworkCore.Query.Internal.ParameterExtractingExpressionVisitor.ExtractParameters(Expression expression)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExtractParameters(Expression query, IParameterValues parameterValues, IDiagnosticsLogger`1 logger, Boolean parameterize, Boolean generateContextAccessors)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.GetEnumerator()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at LinqToDB.EntityFrameworkCore.SqlServer.Tests.IssueTests.Issue73Test() in Q:\Code\Libraries\linq2db.EntityFrameworkCore\Tests\LinqToDB.EntityFrameworkCore.SqlServer.Tests\IssueTests.cs:line 55
This exception was originally thrown at this call stack:
LinqToDB.AnalyticFunctions.RowNumber(LinqToDB.Sql.ISqlExtension)
Microsoft.EntityFrameworkCore.Query.Internal.ParameterExtractingExpressionVisitor.GetValue(System.Linq.Expressions.Expression, out string)
Inner Exception 1:
LinqException: 'RowNumber' is server-side method.
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (9 by maintainers)
Top Results From Across the Web
Why no windowed functions in where clauses?
Title says it all, why can't I use a windowed function in a where clause in SQL Server? This query makes perfect sense:...
Read more >Window function not working on non selected rows
The problem that I've faced is that @NextPartitionRowNum gets NULL as a value, even if there are rows in the table with bigger...
Read more >Why Aren't SQL Window Functions Allowed in GROUP BY?
It's true – the SQL order of operations means window functions aren't allowed in GROUP BY. But you can use them anyway with...
Read more >Window Functions in SQL Server: Part 2-The Frame
I'll now briefly introduce some important window functions supported on SQL Server 2012. After that I'll explain how the window frame works ......
Read more >An Easy Guide to Advanced SQL Window Functions
This article is a guide on advanced window functions for data analysis in SQL. You'll learn through examples about aggregation, ranking, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
You forgot
.ToValue()
Sure, why not.
If you use extensions from Thinktecture we will fail. Anyway, there is extension point and Expression Tree can be corrected to be parseable by our LINQ Translator.
Yeah, asyncs
My fault, read several sentences and missed this part.
Ok, Binary conversion is not present in linq2db, but easily expandable:
And you can use it for your query:
Generated SQL: