Open
Description
openedon Feb 6, 2021
How to reproduce:
dbContext.Set<AnyEntityType>().Select(x => new
{
DateTime = default(DateTime),
x.SomeProperty
}).ToList();
Expected result:
One of:
- Can not translate linq query to sql command
- Parameterize
default(DateTime)
like a variable - Client evaluate
default(DateTime)
- Convert returned string value to
DateTime
type
Actual result:
System.InvalidCastException: Unable to cast object of type 'System.String' to type 'System.DateTime'.
at Microsoft.Data.SqlClient.SqlBuffer.get_DateTime()
at Microsoft.Data.SqlClient.SqlDataReader.GetDateTime(Int32 i)
at lambda_method5(Closure , QueryContext , DbDataReader , ResultContext , SingleQueryResultCoordinator )
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.MoveNext()
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
Generated sql:
SELECT '0001-01-01T00:00:00.0000000' AS [DateTime], [x].[SomeProperty]
FROM [TableName] AS [x]
EF Core version: 5.0.2
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 5.0
Operating system: Windows 10
IDE: Visual Studio 2019 16.8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment