Home
Options

Custom Translation using IMethodCallTranslator failing

I'm using LinqPad 6 on a Windows 10 Enterprise device that's up to date. I'm using custom dbcontexts to execute my statements. When it gets to the linq code(not directly called in LINQ but an existing method that has the LINQ code in it.) where I use a custom method that has a sql translation: DateOrUtcNow it fails to use the translation.It works fine when testing it with a call to the my service. I've checked my OnConfiguring and I'm calling the extension method for registering it.
optionsBuilder.UseSqlServer(connectionString, builder => builder.AddDateOrUtcNowSupport());

Here's the error message:
The LINQ expression 'DbSet()
.Where(c => __coreArguments_Obuids_0.Contains(c.Obuid) && __coreArguments_RegionCodes_1.Contains(c.RegionCode) && c.StartDate < c.EndDate ?? DateTime.Now && __coreArguments_StartDate_2 >= c.StartDate && __coreArguments_EndDate_3 <= c.EndDate
.DateOrUtcNow() || __coreArguments_EndDate_3 > c.StartDate && __coreArguments_EndDate_3 < c.EndDate
.DateOrUtcNow() || __coreArguments_StartDate_2 > c.StartDate && __coreArguments_StartDate_2 < c.EndDate
.DateOrUtcNow())' could not be translated. Additional information: Translation of method 'Earthworks.Microservice.Support.Data.Extensions.DateTimeExtensions.DateOrUtcNow' failed. If this method can be mapped to your custom function, see https://go.microsoft.com/fwlink/?linkid=2132413 for more information.
Translation of method 'Earthworks.Microservice.Support.Data.Extensions.DateTimeExtensions.DateOrUtcNow' failed. If this method can be mapped to your custom function, see https://go.microsoft.com/fwlink/?linkid=2132413 for more information.
Translation of method 'Earthworks.Microservice.Support.Data.Extensions.DateTimeExtensions.DateOrUtcNow' failed. If this method can be mapped to your custom function, see https://go.microsoft.com/fwlink/?linkid=2132413 for more information. Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

And here's the stacktrace:

at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.g__CheckTranslated|15_0(ShapedQueryExpression translated, <>c__DisplayClass15_0& )
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass12_01.<ExecuteAsync>b__0() at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable1.GetAsyncEnumerator(CancellationToken cancellationToken) at System.Runtime.CompilerServices.ConfiguredCancelableAsyncEnumerable1.GetAsyncEnumerator()
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
at Earthworks.Microservice.Support.Data.Extensions.CustomerEquipmentLINQs.GetCustomerEquipmentHistoryQuery(CxpContext cxpContext, MassHaulContext massHaulContext, CoreArguments coreArguments, FilterSelection filter)
at UserQuery.Main(), line 10

Sign In or Register to comment.