Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"No coercion operator is defined between types" when using "in" for a nullable Int property #198

Open
russelg opened this issue Jul 4, 2024 · 1 comment

Comments

@russelg
Copy link

russelg commented Jul 4, 2024

.net 8.0, Breeze 7.3.0.
I get the following error when I try to use "in" for a property that is a nullable Int32:

No coercion operator is defined between types 'System.Collections.Generic.List`1[System.Int32]' and 'System.Nullable`1[System.Int32]'.
   at System.Linq.Expressions.Expression.GetUserDefinedCoercionOrThrow(ExpressionType coercionType, Expression expression, Type convertToType)
   at Breeze.Core.BinaryPredicate.BuildBinaryExpr(Expression expr1, Expression expr2, Operator op)
   at Breeze.Core.BinaryPredicate.ToExpression(ParameterExpression paramExpr)
   at Breeze.Core.BasePredicate.ToLambda(Type entityType)
   at Breeze.Core.QueryBuilder.ApplyWhere(IQueryable source, Type elementType, BasePredicate predicate)
   at Breeze.Core.EntityQueryExtensions.ApplyWhere(EntityQuery eq, IQueryable queryable, Type eleType)
   at Breeze.AspNetCore.BreezeQueryFilterAttribute.OnActionExecuted(ActionExecutedContext context)
   at Microsoft.AspNetCore.Mvc.Filters.ActionFilterAttribute.OnActionExecutionAsync(ActionExecutingContext context, ActionExecutionDelegate next)
   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()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)

Query:

{"where":{"ObjectiveId":{"in":[2886,2888]}}}

Entity:

public class LabelLocation
{
    public int LabelLocationId { get; set; }
    public int LabelId { get; set; }
    public int? ObjectiveId { get; set; }

    public virtual Label Label { get; set; }
    public virtual Objective Objective { get; set; }
}

Ran into this while porting a codebase from .NET Framework 4.8/EF6/ASP.NET to .NET 8.0/EF Core/ASP.NET Core.
The ints are nullable in the old codebase, but this query succeeds successfully in that codebase, albeit the query is OData and not JSON.

@steveschmitt
Copy link
Member

Ah, we must be handling the nullables incorrectly. Thanks for finding this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants