Bug #119461 MySql.EntityFrameworkCore error when using Linq with .Contains in fails
Submitted: 25 Nov 2025 11:32 Modified: 29 Jul 10:42
Reporter: James Britton Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:10.0.0-rc OS:Any
Assigned to: Jose Ramirez Ruiz CPU Architecture:Any

[25 Nov 2025 11:32] James Britton
Description:
Been working on getting ready for .NET 10, but noticed that the 10.0.0-rc package seems to have issues when using .Where in Linq with .Contains call in predicate.

How to repeat:
1. Create an empty API project/

2. Add a BugDbContext that has a DbSet<FakeEntity> property. A fake entity should have an ID property and a name property. Register this DB context in the DI container.

4. Add a BugRepository class that consumes the BugDbContext from the DI container, and also has a public method called trigger that has the following implementation. And register it in the DI container as a scoped service.

"
public async Task Trigger()
    {
        await dbContext.FakeEntities.AddAsync(new FakeEntity { Name = "Fake Entity One" });
        await dbContext.FakeEntities.AddAsync(new FakeEntity { Name = "Fake Entity Two" });
        await dbContext.FakeEntities.AddAsync(new FakeEntity { Name = "Fake Entity Three" });
        await dbContext.FakeEntities.AddAsync(new FakeEntity { Name = "Fake Entity Four" });
        await dbContext.SaveChangesAsync();

        string[] list = ["Fake Entity One", "Fake Entity Four"];
        var result = await dbContext.FakeEntities.Where(x => list.Contains(x.Name))
            .ToListAsync();
        
        Console.WriteLine("Result of Query {Count} found", result.Count);
    }
"

5. After builder.Build a class that gets the BugRepository from the DI container and calls the method trigger. You can do this like this.

"
var service = app.Services.GetRequiredService<BugRepository>();
await service.Trigger();
"

6. now if you run this web application you should see an error like this.

"Unhandled exception. System.InvalidOperationException: Expression '@list' in the SQL tree does not have a type mapping assigned."
[26 Nov 2025 1:03] liming ma
hi

I opened the fix PR.

https://bugs.mysql.com/bug.php?id=119338
[27 Nov 2025 16:37] James Britton
Hi,

great, do you know if that will make it into a fixed version of the pre-release package?

And then is the release of the v10 package likely to be coming in January like previous releases?

Thankyou,
James Britton
[10 Feb 20:31] Jeremy Walsh
Any progress on this? I've also encountered this error and would like a fix.
[27 Apr 10:21] Anson Woo
I am hitting the same wall
[29 Apr 10:42] Torben Hørup
Bug still present with MySql.EntityFrameworkCore 10.0.1 & MySql.Data  9.7.0
[6 May 11:22] Torben Hørup
Bug still present with MySql.EntityFrameworkCore 10.0.7 & MySql.Data  9.7.0
[24 May 10:01] 博迪 杨
Has it not been fixed yet? It's still showing the following error:Expression '@userIdList' in the SQL tree does not have a type mapping assigned
[28 May 1:13] MySQL Admin
Posted by developer: Bug status updated to 'Documenting'
[10 Jun 3:56] Max G
I think the change is partly because Microsoft changed how parameterised collection behaviour in efcore 10.

I've opened a PR that fixes it for me, not sure if it's an ideal fix. Happy to take suggestions though.

https://github.com/mysql/mysql-connector-net/pull/86
[26 Jun 1:07] Jose Ramirez Ruiz
Posted by developer:
 
MySql.EntityFrameworkCore now correctly translates LINQ queries that use .Contains with collection parameters, preserving the appropriate element type mappings. Regression tests were added to prevent recurrence.
[29 Jul 10:42] Edward Gilmore
Posted by developer:
 
 Added the following note to the MySQL Connector/NET 26.7.0 release notes:	
	MySql.EntityFrameworkCore did not correctly translate LINQ
        queries that use .Contains with collection parameters.

        As of this release, they are properly translated, preserving the
        appropriate element type mappings.
[29 Jul 18:23] Lasse Slot
I have just updated to the new 10.0.9 version (from 10.0.7)
And this release fixed for DateOnly and strings... But not for Guids..

Repro: attached minimal console project (no server needed; ToQueryString() alone triggers it). Versions: MySql.EntityFrameworkCore 10.0.9, EF Core 10.0.10, .NET 10.

Expected: WHERE ExternalId IN (@p0, @p1), as already produced for DateOnly/string/int.
Actual: (indsæt exception + stack trace fra outputtet)

Rewriting the same lookup as an OR-chain of scalar Guid equalities translates and binds fine (last probe in the repro), so the Guid type mapping itself appears sound — the failure looks specific to binding the collection as a query parameter.

You can use the belowed for testing it...

------------
Probe.csproj
------------

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <RootNamespace>Probe</RootNamespace>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="MySql.EntityFrameworkCore" Version="10.0.9" />
  </ItemGroup>

</Project>

-----------
Program.cs
-----------

using System.Linq.Expressions;
using Microsoft.EntityFrameworkCore;

namespace Probe;

public sealed class ProbeEntity
{
    public int Id { get; set; }
    public Guid ExternalId { get; set; }
    public DateOnly Day { get; set; }
    public string Code { get; set; } = string.Empty;
    public int Number { get; set; }
}

public sealed class ProbeContext : DbContext
{
    public DbSet<ProbeEntity> Entities => Set<ProbeEntity>();

    // The connection is never opened - ToQueryString() only builds SQL and binds parameters,
    // which is already enough to trigger the failure.
    protected override void OnConfiguring(DbContextOptionsBuilder builder)
        => builder.UseMySQL("Server=localhost;Database=probe;Uid=probe;Pwd=probe;");
}

public static class Program
{
    public static void Main()
    {
        using var context = new ProbeContext();

        Console.WriteLine($"Provider  : {context.Database.ProviderName}");
        Console.WriteLine($"EF Core   : {typeof(DbContext).Assembly.GetName().Version}");
        Console.WriteLine($"Provider v: {ProviderAssemblyVersion()}");
        Console.WriteLine($"Runtime   : {Environment.Version} on {Environment.OSVersion}");
        Console.WriteLine();

        var guids = new[] { Guid.NewGuid(), Guid.NewGuid() };
        var days = new[] { new DateOnly(2026, 6, 25), new DateOnly(2026, 6, 26) };
        var codes = new[] { "alpha", "beta" };
        var numbers = new[] { 1, 2 };

        // --- The failing case: a local Guid collection in Contains() -------------------------
        // All three collection shapes are probed because the symptom differs between them.
        Probe("Guid[]            .Contains(x.ExternalId)",
            () => context.Entities.Where(x => guids.Contains(x.ExternalId)).ToQueryString());

        Probe("List<Guid>        .Contains(x.ExternalId)",
            () => { var l = guids.ToList();
                    return context.Entities.Where(x => l.Contains(x.ExternalId)).ToQueryString(); });

        Probe("HashSet<Guid>     .Contains(x.ExternalId)",
            () => { var s = guids.ToHashSet();
                    return context.Entities.Where(x => s.Contains(x.ExternalId)).ToQueryString(); });

        // EF.Constant does not help either - included to pre-empt that suggestion.
        Probe("EF.Constant(Guid[]).Contains(x.ExternalId)",
            () => context.Entities.Where(x => EF.Constant(guids).Contains(x.ExternalId)).ToQueryString());

        // --- Control cases: the same pattern with other element types works ------------------
        Probe("HashSet<DateOnly> .Contains(x.Day)     [control]",
            () => { var s = days.ToHashSet();
                    return context.Entities.Where(x => s.Contains(x.Day)).ToQueryString(); });

        Probe("HashSet<string>   .Contains(x.Code)    [control]",
            () => { var s = codes.ToHashSet();
                    return context.Entities.Where(x => s.Contains(x.Code)).ToQueryString(); });

        Probe("HashSet<int>      .Contains(x.Number)  [control]",
            () => { var s = numbers.ToHashSet();
                    return context.Entities.Where(x => s.Contains(x.Number)).ToQueryString(); });

        // --- What we currently have to do instead --------------------------------------------
        // Rewriting the lookup as an OR-chain of scalar equalities translates fine, which
        // suggests the Guid type mapping itself is sound and the problem is specific to the
        // way the collection is bound as a query parameter.
        Probe("WORKAROUND: OR-chain of Guid equalities",
            () => context.Entities.Where(ValueIn<ProbeEntity, Guid>(guids, x => x.ExternalId)).ToQueryString());
    }

    private static void Probe(string label, Func<string> buildSql)
    {
        try
        {
            var sql = buildSql();
            Console.WriteLine($"[OK]     {label}");
            Console.WriteLine(Indent(sql));
        }
        catch (Exception ex)
        {
            Console.WriteLine($"[FAILED] {label}");
            Console.WriteLine($"         {ex.GetType().FullName}: {ex.Message}");
            Console.WriteLine(Indent(ex.ToString()));
        }
        Console.WriteLine();
    }

    /// <summary>Builds `x => x.Prop == v1 || x.Prop == v2 || ...` as a stand-in for Contains().</summary>
    private static Expression<Func<TEntity, bool>> ValueIn<TEntity, TValue>(
        IEnumerable<TValue> values, Expression<Func<TEntity, TValue>> selector)
    {
        Expression? body = null;
        foreach (var value in values)
        {
            var equals = Expression.Equal(selector.Body, Expression.Constant(value, typeof(TValue)));
            body = body is null ? equals : Expression.OrElse(body, equals);
        }
        return Expression.Lambda<Func<TEntity, bool>>(
            body ?? Expression.Constant(false), selector.Parameters[0]);
    }

    private static string ProviderAssemblyVersion()
        => AppDomain.CurrentDomain.GetAssemblies()
            .FirstOrDefault(a => a.GetName().Name == "MySql.EntityFrameworkCore")
            ?.GetName().Version?.ToString() ?? "(not loaded)";

    private static string Indent(string text)
        => string.Join(Environment.NewLine,
            text.Split('\n').Select(line => "         " + line.TrimEnd('\r')));
}

---------------
Run with
---------------

dotnet run --project Probe
[29 Jul 18:46] Lasse Slot
I have done some more testing - it's only for Guid Array it's a problem.
I also have created a new bug for it - #121029
https://bugs.mysql.com/bug.php?id=121029
[30 Jul 2:22] Max G
Everything's working for us, although we have wrapper types around our GUIDs
[30 Jul 7:56] Manuel Zulian
Found another regression with Contains (logged at https://bugs.mysql.com/bug.php?id=121034). 

In general the migration to .net 10 has been terrible, started reporting bugs around the connector a year ago: https://bugs.mysql.com/bug.php?id=118460