Dear all,
using EF6 and Oracles EF driver 6.121.2.0, I am stuck a little bit with how code-first migrations should work:
1. (Solved) Had to find a way how to stop the update-database command from using always the "dbo" schema instead of the default login schema name. Solved this by adding the following code into each DbModel:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("");
}
2. (Solved) Now that tables were created, I was stuck with the __MigrationHistory still going to the "dbo" schema. This took me about 4 hours to find out. Need to override a bunch of things:
- Prefix each context with:
[DbConfigurationType(typeof(CustomDbConfiguration))]
public class SavingChangesDbContext : System.Data.Entity.DbContext
...
- CustomDbConfiguration takes care of attaching a custom HistoryContext class:
public class CustomDbConfiguration : DbConfiguration
{
public CustomDbConfiguration()
{
SetHistoryContext(ProviderName, (connection, defaultSchema) => new CustomHistoryContext(connection, defaultSchema));
}
}
- Finally, CustomHistoryContext does the magic of switching off the default schema name:
public class CustomHistoryContext : HistoryContext
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.HasDefaultSchema("");
}
}
Seemed all fine. But Alas! Its not...
3. (UNSOLVED) Automatic migrations do not work, because EF complains about that the location of the __MigrationHistory table should be changed (?), obviously it cannot handle the switching of the schema name. Now I follow the guideline in the ODP.NET readme.txt and always create an initial manual migration script. Applying it the first time - works. Changing nothing and applying the second time - __MigrationHistory is deleted, all other tables NOT and Oracle complains about already existing objects. What to do now?
Literally migration is not useable for me in this way. Do I miss something? And how should this schema thingy work according to your understanding?
BR Florian