Description:
When using MySQL Connector/NET's EF Core provider, translating a LINQ query that calls .Contains() on a locally defined string[] variable fails because MySQLTypeMappingSource has no type mapping registered for the CLR type string[].
Steps to reproduce:
Define an EF Core DbContext using UseMySQL(...).
Execute a LINQ query that uses a string[] variable with .Contains():
var avalue = new[] { "jos" };
var result = context.Employees
.Where(t => avalue.Contains(t.FirstName))
.ToList();
Observe that the query throws an exception because the type mapping source cannot resolve a mapping for string[].
Expected behavior: The query executes successfully, generating the appropriate IN (...) SQL clause and returning matching rows.
Actual behavior: An exception is thrown during query translation because MySQLTypeMappingSource.FindMapping() returns null for CLR type string[] — no mapping branch handles array-of-string types.
Platform/Environment:
MySQL Connector/NET 9.x (EF Core provider)
.NET 10 / EF Core 9+
MySQL Server 5.7+
How to repeat:
Sample code to reproduce: Add the CanUseListContainsWithVariableInQuery test in EFCore/tests/MySql.EFCore.Basic.Tests/FluentAPITests.cs and execute using EF Core 9 or EF Core 10
public void CanUseListContainsWithVariableInQuery()
{
Assume.That(TestUtils.IsAtLeast(5, 7, 0));
var serviceCollection = new ServiceCollection();
serviceCollection.AddEntityFrameworkMySQL()
.AddDbContext<ComputedColumnContext>();
var serviceProvider = serviceCollection.BuildServiceProvider();
using (var context = serviceProvider.GetRequiredService<ComputedColumnContext>())
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
var e = new Employee { FirstName = "Jos", LastName = "Stuart" };
context.Employees.Add(e);
context.SaveChanges();
var avalue = new[] { "jos" } ;
var result = context.Employees.Where(t => avalue.Contains(t.FirstName)).ToList();
Assert.That(result, Has.One.Items);
context.Database.EnsureDeleted();
}
}
Suggested fix:
Root cause: In EFCore/src/Storage/Internal/MySQLTypeMappingSource.cs, the FindMapping override handles Guid as a special CLR type case but does not handle string[]. When EF Core's query translator asks for a type mapping for string[] (needed to parameterize the IN list), null is returned, causing the translation to fail.
Fix: Add an explicit branch in FindMapping to return the _longtextUnicode mapping when clrType == typeof(string[]).
Description: When using MySQL Connector/NET's EF Core provider, translating a LINQ query that calls .Contains() on a locally defined string[] variable fails because MySQLTypeMappingSource has no type mapping registered for the CLR type string[]. Steps to reproduce: Define an EF Core DbContext using UseMySQL(...). Execute a LINQ query that uses a string[] variable with .Contains(): var avalue = new[] { "jos" }; var result = context.Employees .Where(t => avalue.Contains(t.FirstName)) .ToList(); Observe that the query throws an exception because the type mapping source cannot resolve a mapping for string[]. Expected behavior: The query executes successfully, generating the appropriate IN (...) SQL clause and returning matching rows. Actual behavior: An exception is thrown during query translation because MySQLTypeMappingSource.FindMapping() returns null for CLR type string[] — no mapping branch handles array-of-string types. Platform/Environment: MySQL Connector/NET 9.x (EF Core provider) .NET 10 / EF Core 9+ MySQL Server 5.7+ How to repeat: Sample code to reproduce: Add the CanUseListContainsWithVariableInQuery test in EFCore/tests/MySql.EFCore.Basic.Tests/FluentAPITests.cs and execute using EF Core 9 or EF Core 10 public void CanUseListContainsWithVariableInQuery() { Assume.That(TestUtils.IsAtLeast(5, 7, 0)); var serviceCollection = new ServiceCollection(); serviceCollection.AddEntityFrameworkMySQL() .AddDbContext<ComputedColumnContext>(); var serviceProvider = serviceCollection.BuildServiceProvider(); using (var context = serviceProvider.GetRequiredService<ComputedColumnContext>()) { context.Database.EnsureDeleted(); context.Database.EnsureCreated(); var e = new Employee { FirstName = "Jos", LastName = "Stuart" }; context.Employees.Add(e); context.SaveChanges(); var avalue = new[] { "jos" } ; var result = context.Employees.Where(t => avalue.Contains(t.FirstName)).ToList(); Assert.That(result, Has.One.Items); context.Database.EnsureDeleted(); } } Suggested fix: Root cause: In EFCore/src/Storage/Internal/MySQLTypeMappingSource.cs, the FindMapping override handles Guid as a special CLR type case but does not handle string[]. When EF Core's query translator asks for a type mapping for string[] (needed to parameterize the IN list), null is returned, causing the translation to fail. Fix: Add an explicit branch in FindMapping to return the _longtextUnicode mapping when clrType == typeof(string[]).