From ebfe5dbbea429584b0cb01af1c0a0a19a428ee34 Mon Sep 17 00:00:00 2001 From: Ahmet Sevgili Date: Mon, 26 Jan 2026 00:39:27 +0300 Subject: [PATCH] Add support for string[] type mapping in EF Core 10 --- .../Internal/MySQLTypeMappingSource.cs | 2 +- .../StringArrayTest.cs | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 EFCore/tests/MySql.EFCore.Basic.Tests/StringArrayTest.cs diff --git a/EFCore/src/Storage/Internal/MySQLTypeMappingSource.cs b/EFCore/src/Storage/Internal/MySQLTypeMappingSource.cs index 69860b562..c9fec5a88 100644 --- a/EFCore/src/Storage/Internal/MySQLTypeMappingSource.cs +++ b/EFCore/src/Storage/Internal/MySQLTypeMappingSource.cs @@ -284,7 +284,7 @@ protected void Initialize() return mapping; } - else if (clrType == typeof(string)) + else if (clrType == typeof(string) || clrType == typeof(string[])) { var isAnsi = mappingInfo.IsUnicode == false; var isFixedLength = mappingInfo.IsFixedLength == true; diff --git a/EFCore/tests/MySql.EFCore.Basic.Tests/StringArrayTest.cs b/EFCore/tests/MySql.EFCore.Basic.Tests/StringArrayTest.cs new file mode 100644 index 000000000..968143813 --- /dev/null +++ b/EFCore/tests/MySql.EFCore.Basic.Tests/StringArrayTest.cs @@ -0,0 +1,46 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.TestModels.EntitySplitting; +using MySql.EntityFrameworkCore.Basic.Tests.Utils; +using MySql.EntityFrameworkCore.Infrastructure.Internal; +using NUnit.Framework; +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using static MySql.EntityFrameworkCore.Basic.Tests.BasicGuidTests; +namespace MySql.EntityFrameworkCore.Basic.Tests +{ + public class StringArrayTest + { + [Test] + public void TestStringArray() + { + using var context = new ContextStringArray(); + string[] stringArray = new string[] { "TEST" }; + var stockCodeMAtch = context.StringCodeMatch.FirstOrDefault(q => stringArray.Contains(q.Code)); + } + + public class StringCodeMatch + { + [Key] + public int RecordID { get; set; } + public string Code { get; set; } + } + public class ContextStringArray : DbContext + { + public DbSet StringCodeMatch { get; set; } + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (!optionsBuilder.IsConfigured + || optionsBuilder.Options.FindExtension() == null) + { + optionsBuilder.UseMySQL($"server=localhost;user=root;database=DbContextStringArray;CharSet=utf8;Pooling=false;"); + } + } + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + } + } + } +}