You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using the SQL Provider, passing in a DateTime set to DateTimeKind.Local into a dynamic expression throws exception:
System.Data.SqlClient.SqlException: 'Conversion failed when converting date and/or time from character string.'
Exception message: System.Data.SqlClient.SqlException: 'Conversion failed when converting date and/or time from character string.'
Stack trace:
System.Data.SqlClient.SqlException
HResult=0x80131904
Message=Conversion failed when converting date and/or time from character string.
Source=.Net SqlClient Data Provider
StackTrace:
at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady)
at System.Data.SqlClient.SqlDataReader.TryHasMoreRows(Boolean& moreRows)
at System.Data.SqlClient.SqlDataReader.TryReadInternal(Boolean setTimeout, Boolean& more)
at System.Data.SqlClient.SqlDataReader.Read()
at Microsoft.EntityFrameworkCore.Storage.RelationalDataReader.Read()
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer)
at Microsoft.EntityFrameworkCore.SqlServer.Storage.Internal.SqlServerExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__17`2.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at TestHost.Program.Main(String[] args) in C:\EFCore\EFCoreTestBed\Program.cs:line 35
Steps to reproduce
Our SQL database uses datetime columns and we have therefore set the Column Attribute's TypeName property to "datetime".
A query such as the one below works as expected. The timezone/offset info appears to be ignored.
When dynamic expressions are employed, this falls over .
//System.Data.SqlClient.SqlException: //'Conversion failed when converting date and/or time from character string.'varresults= context.Set<Employee>().Where(GetFilterWithLocalDateTime<Employee>(_theLocalDate)).ToList();privatestaticExpression<Func<T,bool>>GetFilterWithLocalDateTime<T>(DateTimevalue){varitemParam= Expression.Parameter(typeof(T),"i");varfilter= Expression.MakeBinary(
ExpressionType.GreaterThan,
Expression.PropertyOrField(itemParam,"Created"),
Expression.Constant(value,typeof(DateTime)));return Expression.Lambda<Func<T,bool>>(filter,new[]{ itemParam });}
Using the SQL Provider, passing in a DateTime set to DateTimeKind.Local into a dynamic expression throws exception:
System.Data.SqlClient.SqlException: 'Conversion failed when converting date and/or time from character string.'
Steps to reproduce
Our SQL database uses datetime columns and we have therefore set the Column Attribute's TypeName property to "datetime".
A query such as the one below works as expected. The timezone/offset info appears to be ignored.
When dynamic expressions are employed, this falls over .
Complete repro here --> https://github.com/avinash-phaniraj-readify/EFCoreTestBed/tree/InconsistentDateTimeHandling.
Further technical details
EF Core version: 2.1.4
Database Provider: Microsoft.EntityFrameworkCore.SqlServer 2.1.4
Operating system: Win 10
IDE: (e.g. Visual Studio 2017 15.8.6)
The text was updated successfully, but these errors were encountered: