AsSubQuery not implemented
moredatapls opened this issue · 2 comments
moredatapls commented
Hey, I want to use your RowNumber
function in my query. I'm using it as shown in your documentation. I'm on version 2.0.0-beta006
of your package and EF Core version 3.1.4
.
This is my query.
var query = Set
.Select(deviceData => new
{
DeviceData = deviceData,
Rank = EF.Functions.RowNumber(deviceData.DeviceId,
EF.Functions.OrderByDescending(deviceData.DateId)
.ThenByDescending(deviceData.TimeId))
})
.AsSubQuery()
.Where(e => e.Rank == 1)
.Select(e => e.DeviceData);
The query fails with the following error message.
System.NotImplementedException : Unhandled method: AsSubQuery
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor
...
Without the AsSubQuery()
it can't translate the statement, which I understand.
System.InvalidOperationException : The LINQ expression 'DbSet<DeviceData>
.Where(d => __Functions_0
.RowNumber(
_: d.DeviceId,
partitionByColumn1: __Functions_0
.OrderByDescending(d.DateId)
.ThenByDescending(d.TimeId)) == 1)' could not be translated. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to either AsEnumerable(), AsAsyncEnumerable(), ToList(), or ToListAsync(). See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
Is the sub query functionality just simply not supported anymore? Do you have an suggestion how to implement this differently?
Thank you!
PawelGerr commented
Did you add the "RowNumberSupport"?
var services = new ServiceCollection()
.AddDbContext<DemoDbContext>(builder => builder
.UseSqlServer("conn-string",
options => options.AddRowNumberSupport());
moredatapls commented
Well that's embarrassing: I did, but not in the test project where I run this query. Thank you! Works now