JonPSmith / EfCore.TestSupport

Tools for helping in unit testing applications that use Entity Framework Core
https://www.thereformedprogrammer.net/new-features-for-unit-testing-your-entity-framework-core-5-code/
Other
352 stars 53 forks source link

Missing logic for verifying DateTime columns #13

Closed lttrung11 closed 5 years ago

lttrung11 commented 5 years ago

I got this error in a call to CompareEfWithDb: DIFFERENT: CommandGroup->Property 'CreateDate', default value sql. Expected = , found = '0001-01-01T00:00:00.0000000'\nDIFFERENT: CommandGroup->Property 'CreateDate', value generated. Expected = Never, found = OnAdd

I may not configure it correctly, but this CreateDate field is a standard DateTime field, with default configuration of EF Core 2.2: public DateTime CreateDate { get; set; }

In SQL Server: [CreateDate] datetime2 NOT NULL

JonPSmith commented 5 years ago

OK, the error says that the database is setting a default DateTime for the column CreateDate when you create a row, and EF Core doesn't know about that. The problem is I have DateTime columns like yours and I don't get that error.

Is the database created by EF Core, or is it an existing database? It feels like there is a default value on that column but that only makes sense if its build with a default value, e.g. [CreateDate] [datetime2](7) NOT NULL DEFAULT GETDATE(). If that is so then you need to add a default value in EF Core and then CompareEfWithDb will be happy (or add this as an Ignore message).

lttrung11 commented 5 years ago

Thank you very much. I will go with GETDATE() default value.