diff --git a/src/EFCore.SqlServer/Storage/Internal/SqlServerVectorTypeMapping.cs b/src/EFCore.SqlServer/Storage/Internal/SqlServerVectorTypeMapping.cs index 1e9cdc6362d..f39938f83d9 100644 --- a/src/EFCore.SqlServer/Storage/Internal/SqlServerVectorTypeMapping.cs +++ b/src/EFCore.SqlServer/Storage/Internal/SqlServerVectorTypeMapping.cs @@ -1,6 +1,9 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Globalization; +using System.Linq.Expressions; +using System.Reflection; using System.Text; using Microsoft.Data.SqlTypes; using Microsoft.EntityFrameworkCore.SqlServer.Internal; @@ -114,7 +117,7 @@ protected override string GenerateNonNullSqlLiteral(object value) builder.Append(','); } - builder.Append(floats[i]); + builder.Append(floats[i].ToString("R", CultureInfo.InvariantCulture)); } builder diff --git a/test/EFCore.SqlServer.Tests/Storage/SqlServerTypeMappingTest.cs b/test/EFCore.SqlServer.Tests/Storage/SqlServerTypeMappingTest.cs index 0577938d0e8..02771a10ab1 100644 --- a/test/EFCore.SqlServer.Tests/Storage/SqlServerTypeMappingTest.cs +++ b/test/EFCore.SqlServer.Tests/Storage/SqlServerTypeMappingTest.cs @@ -8,6 +8,7 @@ using Microsoft.EntityFrameworkCore.SqlServer.Infrastructure.Internal; using Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal; using Microsoft.EntityFrameworkCore.Storage.Internal; +using Microsoft.EntityFrameworkCore.TestUtilities.Xunit; // ReSharper disable InconsistentNaming namespace Microsoft.EntityFrameworkCore.Storage; @@ -478,6 +479,12 @@ public virtual void GenerateCodeLiteral_generates_null_vector_literal() SqlVector.CreateNull(3), "Microsoft.Data.SqlTypes.SqlVector.CreateNull(3)"); + [Fact, UseCulture("de-DE")] + public virtual void GenerateSqlLiteral_formats_vector_floats_with_the_invariant_culture() + => Assert.Equal( + "CAST('[1.5,2.5]' AS VECTOR(2))", + new SqlServerVectorTypeMapping(2).GenerateSqlLiteral(new SqlVector(new float[] { 1.5f, 2.5f }))); + [Fact] public virtual void Vector_default_provider_value_is_zero_vector_of_configured_dimensions() {