4
I have my Migration that has a number close to 6500 records like this:
db.MinhaLista.AddOrUpdate(x => x.Codigo, (new MeuModel { Codigo = "ABC1234", Nome = "Teste "}));
However while running my Migrations as follows:
var migration = new DbMigrator(new Configuration());
migration.Update();
Causes the following Exception:
An unhandled exception of type 'System.StackOverflowException' occurred
//Descrição:
{Cannot evaluate expression because the current thread is in a stack overflow state.}
What I’ve currently tested and verified is:
- Inside all records there is no model with the property Repeated code
- I tried using db.Savechanges() between an X number in X records (from 1000 to 1000)
[Edit] The call of this Migrator is using Setinitializer
static DbContext()
{
Database.SetInitializer<AppDbContext>(new CustomAndMigrationDatabase<DbContext, Configuration>());
}
Where the class CustomAndMigrationDatabase
receives Dbcontext and Configuration, thus performing the Dbmigrator instance as follows:
var migration = new DbMigrator(new TMigrationsConfiguration());
if (migration.GetPendingMigrations().Any())
{
migration.Update();
}
Ask the context constructor as well. Possibly the problem is there.
– Leonel Sanches da Silva