Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Filtering: `FilterExpressionBuilder.HasValue` / `HasValueAndAlso` wrap `HasValue` in `Expression.IsTrue`, which EF Core cannot translate

Open Beginner friendly
#10,567 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
75/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp
Domain
api, backend

Research direction

Start with src/HotChocolate/Data/src/Data/Filters/Expressions/FilterExpressionBuilder.cs, especially HasValue and HasValueAndAlso. Run the linked reproduction script against the reported EF Core setup and inspect how the expressions differ from the translating NotNull helpers. Done means both HasValue helpers translate on EF Core and the reproduction succeeds.

Written by the indexing model from the issue text.

Description

🌶️ hot chocolate
Product

Hot Chocolate

Version

16.6.8

Link to minimal reproduction

https://github.com/AdCodicem/dotnet-upstream-repros/tree/main/hotchocolate-data-hasvalue-istrue-efcore

Steps to reproduce
  1. Clone the repository and run ./hotchocolate-data-hasvalue-istrue-efcore/repro.sh (bash; Git Bash works on Windows). It runs dotnet run on a console project referencing HotChocolate.Data 16.6.8 and Microsoft.EntityFrameworkCore.Sqlite 10.0.13, with an in-memory SQLite database; no server is needed.
  2. The program builds four predicates over Order.Quantity (int?) with the public FilterExpressionBuilder, the helper a custom QueryableOperationHandlerBase builds its expression with, and runs each in memory and through EF Core:
var order = Expression.Parameter(typeof(Order), "o");
var quantity = Expression.Property(order, nameof(Order.Quantity));               // int?
var greaterThanFive = Expression.GreaterThan(
    Expression.Property(quantity, nameof(Nullable<int>.Value)), Expression.Constant(5));

FilterExpressionBuilder.HasValueAndAlso(quantity, greaterThanFive); // fails on EF Core
FilterExpressionBuilder.HasValue(quantity);                         // fails on EF Core
FilterExpressionBuilder.NotNullAndAlso(quantity, greaterThanFive);  // translates
Expression.AndAlso(Expression.Property(quantity, "HasValue"), greaterThanFive); // translates
  1. REPRO_HC_VERSION=16.7.0-p.28 ./repro.sh runs the same against the latest 16.7 preview.
What is expected?

HasValue(x) and HasValueAndAlso(x, condition) translate on EF Core like NotNull(x) and NotNullAndAlso(x, condition) do, to x IS NOT NULL: EF Core translates Nullable<T>.HasValue itself.

What is actually happening?

FilterExpressionBuilder.HasValue returns Expression.IsTrue(Expression.Property(expression, "HasValue")). EF Core has no translation for a UnaryExpression of node type IsTrue, so any filter built with HasValue or HasValueAndAlso throws The LINQ expression ... could not be translated on a relational provider. In memory the four predicates agree. Same result on 16.7.0-p.28; main has the same code (src/HotChocolate/Data/src/Data/Filters/Expressions/FilterExpressionBuilder.cs, HasValue).

Relevant log output
== FilterExpressionBuilder.HasValueAndAlso(o.Quantity, o.Quantity.Value > 5)
   expression: o => (IsTrue(o.Quantity.HasValue) AndAlso (o.Quantity.Value > 5))
   in memory:  [3]
   EF Core:    !! InvalidOperationException: The LINQ expression 'DbSet<Order>()
               .Where(o => IsTrue(o.Quantity.HasValue) && o.Quantity.Value > 5)' 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 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

== FilterExpressionBuilder.HasValue(o.Quantity)
   expression: o => IsTrue(o.Quantity.HasValue)
   in memory:  [1, 3]
   EF Core:    !! InvalidOperationException: The LINQ expression 'DbSet<Order>()
               .Where(o => IsTrue(o.Quantity.HasValue) )' could not be translated. [...]

== FilterExpressionBuilder.NotNullAndAlso(o.Quantity, o.Quantity.Value > 5)
   expression: o => ((o.Quantity != null) AndAlso (o.Quantity.Value > 5))
   in memory:  [3]
   EF Core:    [3]
   SQL:        WHERE "o"."Quantity" IS NOT NULL AND "o"."Quantity" > 5

== Expression.AndAlso(o.Quantity.HasValue, o.Quantity.Value > 5), no IsTrue
   expression: o => (o.Quantity.HasValue AndAlso (o.Quantity.Value > 5))
   in memory:  [3]
   EF Core:    [3]
   SQL:        WHERE "o"."Quantity" IS NOT NULL AND "o"."Quantity" > 5
Additional context

HotChocolate.Data does not call HasValue or HasValueAndAlso itself (they came with #5760 and nothing in src/HotChocolate/Data uses them; the built-in handlers guard a nullable instance with NotNullAndAlso), so this only reaches custom operation handlers, for which FilterExpressionBuilder is the public toolbox. We hit it in a handler filtering a Nullable<TStruct> member and switched to x != null. Dropping the Expression.IsTrue wrapper (HasValue is already a bool) would make both helpers translate.

Investigation and write-up assisted by Claude (Anthropic); the linked repro was run on Windows 11 (10.0.26200), .NET SDK 10.0.402, HotChocolate.Data 16.6.8 and 16.7.0-p.28, Microsoft.EntityFrameworkCore.Sqlite 10.0.13, and I reviewed this report.

Dominant language
C#
Stars
5.8k
Forks
810
Avg merge
19h 37m
Merged PRs (30d)
156

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from ChilliCream/graphql-platform

All issues in ChilliCream/graphql-platform

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.