Hi,
We are using the Zero framework for Single Tenancy and would like to eliminate the EF Migrator tool from our development and build pipeline.
Normally with EF Code First you should be able to use the MigrateDatabaseToLatestVersion initializer to create a new database, run migrations and then run the seed. However this does not seem to work with Zero.
We have added the following to the ZeroDbContext:
Database.SetInitializer(new MigrateDatabaseToLatestVersion<ZeroDbContext, Configuration>());
However when running the solution without an existing database the following error occurs :
"CREATE DATABASE statement not allowed within multi-statement transaction"
If we create an empty database manually first (not ideal, but acceptable) then the migrations appear to run but not the seed and we have the following error:
"There is no tenant with given id: 1"
This error is caused by the seed not executing.
Can you please advise how we can eliminate the need for the Migrator and have the migrations and seed run automatically.
Kind Regards.
1 Answer(s)
-
0
Hi,
In order to skip that exception, transaction must be disabled just like we do it in Migrator project. Instead of doing it in DbContext, you can do it in your Application Start.
After ABP initialization, just run a code similar in Migrator tool.
If you have difficulties or problems applying this, please let us know.
Thanks.