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
When doing a select query into a class with a Nullable from a database model class property that's a Nullable it seems the conversion wants to return a DateTime.MinValue. I'd expect all of the below tests to return null.
Steps to reproduce
voidMain(){vartest1=Coupons.Select(r =>new{r.EndDateTime});foreach(vart1intest1){Console.WriteLine("Test1");Console.WriteLine(t1.EndDateTime);Console.WriteLine();}vartest2=Coupons.Select(c =>newDTO{DT=c.EndDateTime==null?(DateTime?)null:c.EndDateTime.Value.DateTime.Date});foreach(vart2intest2){Console.WriteLine("Test2");Console.WriteLine(t2.DT);Console.WriteLine();}vartest3=Coupons.ToList().Select(c =>newDTO{DT=c.EndDateTime==null?(DateTime?)null:c.EndDateTime.Value.DateTime.Date});foreach(vart3intest3){Console.WriteLine("Test3");Console.WriteLine(t3.DT);Console.WriteLine();}}publicclassDTO{publicDateTime?DT{get;set;}}// This is a database model class. There's also nothing in the constructor that modifies this property.publicclassCoupons{publicDateTimeOffset?EndDateTime{get;set;}}
Console
Test1
null
Test2
1/1/0001 12:00:00 AM
Test3
null
Further technical details
EF Core version: 3.1.2
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET Standard 2.1
Operating system: Windows 10 64bit
IDE: Visual Studio 2019 16.5.5
Activity
smitpatel commentedon May 16, 2020
Same root cause as #20633
Query: Don't read default value from databases
Query: Don't read default value from databases
Query: Don't read default value from databases (#21668)