我正在尝试使用https://github.com/bubibubi/sqliteef6migrations库进行迁移。它的主要例子是正常的:
internal sealed class ContextMigrationConfiguration : DbMigrationsConfiguration<Context>
{
public ContextMigrationConfiguration()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = true;
SetSqlGenerator("System.Data.SQLite", new SQLiteMigrationSqlGenerator());
}
}
但是当我尝试这样做时,它失败了:
public sealed class ContextMigrationConfiguration : DbMigrationsConfiguration<UnitOfWork>
{
private readonly bool _pendingMigrations;
public ContextMigrationConfiguration()
{
AutomaticMigrationsEnabled = true;
AutomaticMigrationDataLossAllowed = true;
SetSqlGenerator("System.Data.SQLite", new SQLiteMigrationSqlGenerator());
var migrator = new DbMigrator(this);
_pendingMigrations = migrator.GetPendingMigrations().Any();
if (_pendingMigrations)
{
migrator.Update();
Seed(new UnitOfWork());
}
}
protected sealed override void Seed(UnitOfWork context)
{
// Initialization
}
}
_pendingMigrations = migrator.GetPendingMigrations().Any();
失败
上的System.ObjectDisposedException
.GetPendingMigrations()
| ObjectName | “SQLiteConnection”|来源| “System.Data.SQLite”
| StackTrace | “恩 System.Data.SQLite.SQLiteConnection.CheckDisposed()\ r \ n en System.Data.SQLite.SQLiteConnection.get_State()\ r \ n en System.Data.Entity.Internal.RepositoryBase.CreateConnection()\ r \ n en System.Data.Entity.Migrations.History.HistoryRepository.QueryExists(字符串 contextKey)\ r \ n en System.Data.Entity.Migrations.History.HistoryRepository.Exists(字符串 contextKey)\ r \ n en System.Data.Entity.Migrations.History.HistoryRepository.GetPendingMigrations(IEnumerable`1 localMigrations)\ r \ n en System.Data.Entity.Migrations.DbMigrator.GetPendingMigrations(个)\ r \ n
en QApps.DataLayer.Context.ContextMigrationConfiguration..ctor()zh D:\ Projects \ ... \ Context \ UnitOfWork.cs:línea91“
我正在尝试使用一些测试数据来初始化数据库,但如果我直接使用Seed,则每次启动应用程序时都会设置数据,所以我只是在更新后尝试播种。
我还没有启用迁移的一件事,我只是用它来创建数据库并用一些测试数据填充它。
也许问题与库无关,而与代码的另一部分无关。任何帮助都会被贬低。