I have an ASP.NET Core application which connects to a sqlite database. Although I use all DateTime
values as UTCs (with DateTime.UtcNow
and value.ToUniversalTime()
), I still get datetime value DateTimeKind.Unspecified
from the database.
I tried to set DateTimeKind=Utc
in the connection string, but then I get the
System.ArgumentException: Keyword not supported: 'datetimekind'
for the code
var context = services.GetRequiredService<ApplicationDbContext>();
context.Database.Migrate();
I also already tried this solution with:
services.AddDbContext<ApplicationDbContext>(options =>
{
var connectionString = Configuration.GetConnectionString("DatabaseConnection");
var conn = new SQLiteConnection(connectionString);
conn.Open();
var x = options.UseSqlite(
conn
);
});
but it still produces the same error while migration.
I got the feeling that the Migrate
function creates it's own connection, because the stacktrace looks like:
at Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.GetIndex(String keyword)
at Microsoft.Data.Sqlite.SqliteConnectionStringBuilder.set_Item(String keyword, Object value)
at System.Data.Common.DbConnectionStringBuilder.set_ConnectionString(String value)
at Microsoft.Data.Sqlite.SqliteConnectionStringBuilder..ctor(String connectionString)
at Microsoft.EntityFrameworkCore.Sqlite.Storage.Internal.SqliteDatabaseCreator.Exists()
at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.Exists()
at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.Migrate(String targetMigration)
at Microsoft.EntityFrameworkCore.RelationalDatabaseFacadeExtensions.Migrate(DatabaseFacade databaseFacade)
One notices that the stacktraces goes through
Microsoft.Data.Sqlite.SqliteConnectionStringBuilder
But I don't know why it does.
The call to the migration looks like this:
var context = services.GetRequiredService<ApplicationDbContext>();
context.Database.Migrate();
so as to my understanding the context
should include my SQLite connection based on the SQLiteConnection
class.