Closed bondpp7-2 closed 2 years ago
I was unable to reproduce the issue. I setup a new .Net 6 Asp.Net Core website and unit test project and created a unit test with the WebApplicationFactory
pointing to the Program
class of my website which calls the options.UseNodaTime
method.
Perhaps in your setup of the unit test services, you have called a different AddDbContext
method which would replace the one in the website project?
I'm not sure what the issue could be. This worked fine with .NET5; we upgraded to .NET6 and moved to the new namespace for "UseNoda()", but now it's not able to understand LocalDate columns.
I am unable to get it to work, even in a simple demo app (see attached archive TestNet6EF.zip )
At first I was thinking it was just the tests and related to the WebApplicationFactory, but it seems I can't get it to work at all. I'm almost certainly doing something wrong, I'm just not sure what.
Okay, I was able to get this to work on a small test project, so it's definitely on my end; I'll do a diff and see where I went wrong on the other.
Turns out it was an issue with my column definition in the EntityConfig; "smalldatetime" (failed) vs "date" (works). SqlServerNodaTime works as designed.
@bondpp7-2 Great! Glad you were able to get it figured out.
My tests which utilize WebApplicationFactory are not benefiting from the 'UseNoda()' extension. There are not compile errors, and at runtime, things work as expected. During the tests, however, I receive
...is of type 'LocalDate' which is not supported by the current database provider.
I'm using
<PackageReference Include="SimplerSoftware.EntityFrameworkCore.SqlServer.NodaTime" Version="6.0.0" />
withservices.AddDbContext<MyDBContext>(options => options.UseSqlServer(connectionString, options => options.UseNodaTime()) );
I'm not sure why the use of WebApplicationFactory would cause a difference in behavior. Perhaps there's a simple approach to resolve this?