Skip to content

Commit 5e1469c

Browse files
authored
Better detection of string store types on primitive collections (#30920)
1 parent 00c6ac4 commit 5e1469c

File tree

3 files changed

+377
-162
lines changed

3 files changed

+377
-162
lines changed

src/EFCore.SqlServer/Storage/Internal/SqlServerTypeMappingSource.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -437,16 +437,20 @@ public SqlServerTypeMappingSource(
437437
return null;
438438
}
439439

440-
switch (mappingInfo.StoreTypeNameBase)
440+
switch (mappingInfo.StoreTypeNameBase?.ToLowerInvariant())
441441
{
442+
case "nvarchar":
443+
case "varchar":
442444
case "char varying":
443445
case "char":
444446
case "character varying":
445447
case "character":
448+
case "nchar":
446449
case "national char varying":
447450
case "national character varying":
448451
case "national character":
449-
case "varchar":
452+
case "text":
453+
case "ntext":
450454
case null:
451455
break;
452456
default:

test/EFCore.Relational.Tests/Storage/RelationalTypeMapperTestBase.cs

+8
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ protected IMutableEntityType CreateEntityType<TEntity>()
2020
builder.Entity<MyPrecisionType>().Property(e => e.PrecisionOnly).HasPrecision(16);
2121
builder.Entity<MyPrecisionType>().Property(e => e.PrecisionAndScale).HasPrecision(18, 7);
2222
builder.Entity<MyTypeWithIndexAttribute>();
23+
builder.Entity<MyTypeWithIndexAttributeOnCollection>();
2324

2425
return builder.Model.FindEntityType(typeof(TEntity));
2526
}
@@ -203,4 +204,11 @@ protected class MyTypeWithIndexAttribute
203204
public int Id { get; set; }
204205
public string Name { get; set; }
205206
}
207+
208+
[Index(nameof(Ints))]
209+
protected class MyTypeWithIndexAttributeOnCollection
210+
{
211+
public int Id { get; set; }
212+
public IEnumerable<int> Ints { get; set; }
213+
}
206214
}

0 commit comments

Comments
 (0)