Override "dbo" schema name in EntityFramework Code First Migrations Override "dbo" schema name in EntityFramework Code First Migrations oracle oracle

Override "dbo" schema name in EntityFramework Code First Migrations


Go to Migrations -> Configuration.cs and below mentioned code. This fix worked for me!

class Configuration : DbMigrationsConfiguration<CodeFirstOracleProject.Context>{    public Configuration()    {        AutomaticMigrationsEnabled = false;        var historyContextFactory = GetHistoryContextFactory("Oracle.ManagedDataAccess.Client");        SetHistoryContextFactory("Oracle.ManagedDataAccess.Client",                                 (dbc, schema) => historyContextFactory.Invoke(dbc, "YourSchemaName"));    }}


Try runnig Enable-Migrations -force again. Then run Add-Migration SomeDescription –IgnoreChanges. After that, run "Update-Database - Verbose". This worked to me


I successfully tried the following inside the Configuration : DbMigrationsConfiguration class for Oracle, in order to change the history schema to "Test":

var historyContextFactory = GetHistoryContextFactory("Oracle.ManagedDataAccess.Client");SetHistoryContextFactory("Oracle.ManagedDataAccess.Client",                         (dbc, schema) => historyContextFactory.Invoke(dbc, "Test"));

So basically, instead of trying to register a custom history context with unchanged default schema, I tried to register the default history context with changed default schema.

The result: when I run Update-Database -Script, the resulting script contains the new schema for creation of the __MigrationHistory table as well as for inserting the new history values:

create table "Test"."__MigrationHistory"    -- ...insert into "Test"."__MigrationHistory"("MigrationId", "ContextKey", "Model", "ProductVersion") ...

However, lets be perfectly clear: I just tried what I expected to work by intuition and it did work for me. I didn't find any reliable documentation to support this solution.