I'm trying to test making SQLite database using EF.Core. Despite all my effort to get it work, it still not working as intended and i don't know why. The Add-Migration command works ok but then when i try to Update-DataBase it throws System.NullReferenceException. Anyone has an idea why is that? Below you can see the code and the exception.
public class TestModel
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Id { get; set; }
public string Name { get; set; }
}
private const string ConnectionString = "Data Source = AutoHome.db";
public DbSet<TestModel> testModels { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
options.UseSqlite(ConnectionString);
base.OnConfiguring(options);
}
PM> Update-DataBase Build started... Build succeeded. System.NullReferenceException: Object reference not set to an instance of an object. at Microsoft.Data.Sqlite.SqliteConnection.Open() at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection(Boolean errorsExpected) at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected) 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.Design.Internal.MigrationsOperations.UpdateDatabase(String targetMigration, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabaseImpl(String targetMigration, String contextType) at Microsoft.EntityFrameworkCore.Design.OperationExecutor.UpdateDatabase.<>c__DisplayClass0_0.<.ctor>b__0() at Microsoft.EntityFrameworkCore.Design.OperationExecutor.OperationBase.Execute(Action action) Object reference not set to an instance of an object. PM>
It seems that it is an issue with Microsoft.Data.Sqlite.Core. I just added a reference Microsoft.Data.Sqlite and everything works right now.
OBS!!!
There is already an open ticket about this GitHub/EF/Issues