zzzprojects / Eval-Expression.NET

C# Eval Expression | Evaluate, Compile, and Execute C# code and expression at runtime.
https://eval-expression.net/
Other
459 stars 86 forks source link

"Ambiguous match found" using IncludeFilter and Dynamic Execute #145

Closed JonathanMagnan closed 1 year ago

JonathanMagnan commented 1 year ago

Here is what to include in your request to make sure we implement a solution as quickly as possible.

1. Description

Trying to execute the following code:

var queryResult = myContext.Execute<IEnumerable<RemittanceEntity>>("Where(x => x.DeletedOn == null).IncludeFilter(x => x.Payments)").ToList();

and I receive an error that the IncludeFilter is ambiguous. When the same code is used outside of the Execute (directly against the DBSet), it works. IncludeFilter on other entities also works with Execute. Additionally, Where with the Payments entity also works using Execute.

2. Exception

Exception message: "Oops! Ambiguous match found for: 'IncludeFilter'. The error occurred for expression \".\" at position 140 near \".IncludeFilter(x => x.Pay\".",

Stack trace:

at .(ExpressionScope , Expression , Type , String , List`1 , SyntaxNode , List`1 , Boolean )
   at .(ExpressionScope , Expression , Type , String , List`1 , Boolean , List`1 , SyntaxNode , Expression& )
   at .(ExpressionScope , SyntaxNode , Type , Expression , List`1 )
   at .(ExpressionScope , SyntaxNode , Expression , Boolean )
   at .(ExpressionScope , SyntaxNode , Expression , Boolean )
   at .(ExpressionScope , SyntaxNode , Expression , Boolean )
   at .[](EvalContext , String , IDictionary`2 , Type , EvalCompilerParameterKind , ExpressionScope , String , Boolean , Boolean )
   at .[](EvalContext , String , IDictionary`2 , Type , EvalCompilerParameterKind , Boolean , Boolean , Boolean )
   at Z.Expressions.EvalLinq.Execute(String code, Boolean isQueryable, Expression exp, Object[] parameters)
   at System.Linq.QueryableDynamic.Execute[TValue](IQueryable source, String expression, Object parameter)
   at DirectClaim.Claims.Core.Handlers.Queries.Remittance.GetRemittancesHandler.Handle(GetRemittancesRequest request)
   at InfinityBehavioral.Common.Data.Handlers.EfCoreRequestHandler`2.Handle(TRequest request, CancellationToken cancellationToken)
   at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestPreProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestPostProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestExceptionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestExceptionActionProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestPreProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at MediatR.Pipeline.RequestPostProcessorBehavior`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at InfinityBehavioral.Common.Cqrs.Handlers.PipelineBehaviors.UtcDateTimeHandler`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at InfinityBehavioral.Common.Cqrs.Handlers.PipelineBehaviors.EncryptionHandler`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at InfinityBehavioral.Common.Cqrs.Handlers.PipelineBehaviors.ValidationHandlerAsync`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at InfinityBehavioral.Common.Cqrs.Handlers.PipelineBehaviors.ContextParserHandlerAsync`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at InfinityBehavioral.Common.Cqrs.Handlers.PipelineBehaviors.TenantScopeEvaluationHandlerAsync`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at InfinityBehavioral.Common.Cqrs.Handlers.PipelineBehaviors.AuditHandler`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at InfinityBehavioral.Common.Cqrs.Handlers.PipelineBehaviors.CorrelationHandlerAsync`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at InfinityBehavioral.Common.Data.Handlers.PipelineBehaviors.DbTransactionWrapperHandlerAsync`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at InfinityBehavioral.Common.Cqrs.Handlers.PipelineBehaviors.UtcDateTimeHandler`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at InfinityBehavioral.Common.Cqrs.Handlers.PipelineBehaviors.EncryptionHandler`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at InfinityBehavioral.Common.Cqrs.Handlers.PipelineBehaviors.ValidationHandlerAsync`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at InfinityBehavioral.Common.Cqrs.Handlers.PipelineBehaviors.ContextParserHandlerAsync`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at InfinityBehavioral.Common.Cqrs.Handlers.PipelineBehaviors.TenantScopeEvaluationHandlerAsync`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at InfinityBehavioral.Common.Cqrs.Handlers.PipelineBehaviors.AuditHandler`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at InfinityBehavioral.Common.Cqrs.Handlers.PipelineBehaviors.CorrelationHandlerAsync`2.Handle(TRequest request, CancellationToken cancellationToken, RequestHandlerDelegate`1 next)
   at DirectClaim.Claims.Api.Controllers.Remittance.RemittanceController.GetRemittances(GetRemittancesRequest request) in D:\\Dev\\Infinity\\Direct Claim Repos\\DirectClaim.Claims\\DirectClaim.Claims.Api\\Controllers\
emittance\
emittanceController.cs:line 25
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Logged|12_1(ControllerActionInvoker invoker)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at InfinityBehavioral.Common.Logging.ExceptionHandling.Middleware.ExceptionHandlingMiddleware.Invoke(HttpContext context)

4. Any further technical details

.NET Core 6

Original Post: https://github.com/zzzprojects/System.Linq.Dynamic.Core/issues/708

JonathanMagnan commented 1 year ago

Hello @szavoda,

You currently using a method of EF Plus. However, C# Eval is not aware of our third-party library.

You need to register the method to use IncludeFilter in a dynamic expression.

You can register all methods of EF Plus using the following code:

EvalManager.DefaultContext.RegisterAssembly(typeof(Z.EntityFramework.Plus.Audit).Assembly);

After registering the assembly, you will now be able to use your code successfully.

Best Regards,

Jon

szavoda commented 1 year ago

Hi @JonathanMagnan

I tried adding the statement, but it gave the same results. I placed it as the last statement in the program startup before the App.Run as well as a few other positions, but with the same results.

Thanks for the help!

Shawn

JonathanMagnan commented 1 year ago

Hello @szavoda ,

Here is an online example created by my developer: https://dotnetfiddle.net/yQVJyk

Could you try to reproduce the issue if you still have it after looking at this example?

Best Regards,

Jon

szavoda commented 1 year ago

@JonathanMagnan -

I believe that there has to be something else wrong with my implementation specifically. I am able to the the IncludeFilter dynamically against other entities - it is only when I attempt to include the "Payment" Entity that I get the error. I am going to start to tear this down to the basics and see if I can locate my issue.

As a side note, I am able to use the IncludeFilter dynamically without registering the assembly on the other entities that are working.

JonathanMagnan commented 1 year ago

Hello @szavoda

Any update on your issue?

Let me know if you need further assistance.

Best regards,

Jon

szavoda commented 1 year ago

Hi - I am going to be tackling this some more today. The only difference between my entities and the ones that work that I can see so far is that I am using SQL Temporal Tables. I will be trying to recreate in our project and then try to move to a shared project for your team.

Thanks!

Shawn

JonathanMagnan commented 1 year ago

Hello @szavoda

Unfortunately, since we didn't hear from you I will close this issue.

As previously mentioned, we need a runnable project to be able to assist you.

We will reopen the issue if a project is received.

Feel free to contact us for questions, issues or feedback.

Best Regards,

Jon