Bug #119461 MySql.EntityFrameworkCore error when using Linq with .Contains in fails
Submitted: 25 Nov 11:32 Modified: 27 Nov 16:37
Reporter: James Britton Email Updates:
Status: Open Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:10.0.0-rc OS:Any
Assigned to: CPU Architecture:Any

[25 Nov 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 1:03] liming ma
hi

I opened the fix PR.

https://bugs.mysql.com/bug.php?id=119338
[27 Nov 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