dotnet / ef6

This is the codebase for Entity Framework 6 (previously maintained at https://entityframework.codeplex.com). Entity Framework Core is maintained at https://github.com/dotnet/efcore.
https://docs.microsoft.com/ef/ef6
MIT License
1.43k stars 545 forks source link

SQL statements are emitted in a culture-aware format #2102

Closed Epic-Santiago closed 1 year ago

Epic-Santiago commented 1 year ago

When the SQL statement is emitted, it is written using the current culture rather than CultureInfo.InvariantCulture. This can cause the SQL statement to be invalid. For example, in Finnish, the NumberFormat.NegativeSign is − (0x2212) instead of - (0x2D). Negative longs and ints (and probably others) become invalid in SQL because instead of -1, −1 is written.

Repro:

CultureInfo.CurrentCulture = CultureInfo.GetCultureInfo("fi-FI");

const int negativeInt = -1;

var row = db.MyTable
    .Where(r => r.MyInt > negativeInt)
    .First();

Include stack traces

System.Data.Entity.Core.EntityCommandExecutionException HResult=0x8013193C Message=An error occurred while executing the command definition. See the inner exception for details. Source=EntityFramework StackTrace: at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior) at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues) at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess) at System.Data.Entity.Core.Objects.ObjectQuery1.<>c__DisplayClass41_0.b0() at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func1 operation) at System.Data.Entity.Core.Objects.ObjectQuery1.<System.Collections.Generic.IEnumerable.GetEnumerator>b31_0() at System.Data.Entity.Internal.LazyEnumerator1.MoveNext() at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable1 source, Boolean& found) at System.Linq.Enumerable.First[TSource](IEnumerable1 source) at System.Linq.Queryable.First[TSource](IQueryable1 source) at ConsoleApp1.Program.Main() in C:\Users\spalacios\OneDrive - Epicor\Stories\ERPS-218804\ConsoleApp1\Program.cs:line 20

This exception was originally thrown at this call stack: System.Data.SqlClient.SqlConnection.OnError(System.Data.SqlClient.SqlException, bool, System.Action) System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(System.Data.SqlClient.TdsParserStateObject, bool, bool) System.Data.SqlClient.TdsParser.TryRun(System.Data.SqlClient.RunBehavior, System.Data.SqlClient.SqlCommand, System.Data.SqlClient.SqlDataReader, System.Data.SqlClient.BulkCopySimpleResultSet, System.Data.SqlClient.TdsParserStateObject, out bool) System.Data.SqlClient.SqlDataReader.TryConsumeMetaData() System.Data.SqlClient.SqlDataReader.MetaData.get() System.Data.SqlClient.SqlCommand.FinishExecuteReader(System.Data.SqlClient.SqlDataReader, System.Data.SqlClient.RunBehavior, string) System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(System.Data.CommandBehavior, System.Data.SqlClient.RunBehavior, bool, bool, int, out System.Threading.Tasks.Task, bool, System.Data.SqlClient.SqlDataReader) System.Data.SqlClient.SqlCommand.ExecuteReader(System.Data.CommandBehavior) System.Data.Entity.Infrastructure.Interception.InternalDispatcher.Dispatch<TTarget, TInterceptionContext, TResult>(TTarget, System.Func<TTarget, TInterceptionContext, TResult>, TInterceptionContext, System.Action<TInterceptor, TTarget, TInterceptionContext>, System.Action<TInterceptor, TTarget, TInterceptionContext>) System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(System.Data.Common.DbCommand, System.Data.Entity.Infrastructure.Interception.DbCommandInterceptionContext) ... [Call Stack Truncated]

Inner Exception 1: SqlException: Incorrect syntax near '−'.

Include provider and version information

EF version: 6.4.4 Database provider: System.Data.SqlClient 4.8.5 Target framework: net6.0 Operating system: Windows 10 IDE: Visual Studio 2022 17.5.2

ajcvickers commented 1 year ago

This issue has been closed because EF6 is no longer being actively developed. We are instead focusing on stability of the codebase, which means we will only make changes to address security issues. See the repo README for more information.