You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
abp/docs/en/Entity-Framework-Core-Oracl...

4.4 KiB

Switch to EF Core Oracle Provider

This document explains how to switch to the Oracle database provider for the application startup template which comes with SQL Server provider pre-configured.

ABP Framework provides integrations for two Oracle packages:

You can choose one of the package you want. If you don't know the differences of the packages, please search for it. ABP Framework only provides integrations we don't provide support for these 3rd-party libraries.

Replace the Volo.Abp.EntityFrameworkCore.SqlServer Package

.EntityFrameworkCore project in the startup solution depends on the Volo.Abp.EntityFrameworkCore.SqlServer NuGet package. Remove this package and add the same version of one of the packages based on your preference;

Replace the Module Dependency

Find YourProjectNameEntityFrameworkCoreModule class inside the .EntityFrameworkCore project, remove typeof(AbpEntityFrameworkCoreSqlServerModule) from the DependsOn attribute. Then add one of the modules to the dependency list, based on the packages you've chosen:

  • typeof(AbpEntityFrameworkCoreOracleModule) (official Oracle package). Also replace using Volo.Abp.EntityFrameworkCore.SqlServer; with using Volo.Abp.EntityFrameworkCore.Oracle;
  • typeof(AbpEntityFrameworkCoreOracleDevartModule) (Devart package). Also replace using Volo.Abp.EntityFrameworkCore.SqlServer; with using Volo.Abp.EntityFrameworkCore.Oracle.Devart;

UseOracle()

Find UseSqlServer() calls in your solution, replace with UseOracle(). Check the following files:

  • YourProjectNameEntityFrameworkCoreModule.cs inside the .EntityFrameworkCore project.
  • YourProjectNameMigrationsDbContextFactory.cs inside the .EntityFrameworkCore.DbMigrations project.

In the CreateDbContext() method of the YourProjectNameMigrationsDbContextFactory.cs, replace the following code block

var builder = new DbContextOptionsBuilder<YourProjectNameMigrationsDbContext>()
                .UseSqlServer(configuration.GetConnectionString("Default"));

with this one

var builder = (DbContextOptionsBuilder<YourProjectNameMigrationsDbContext>)
	new DbContextOptionsBuilder<YourProjectNameMigrationsDbContext>().UseOracle
	(
		configuration.GetConnectionString("Default")
	);

Depending on your solution structure, you may find more code files need to be changed.

Change the Connection Strings

Oracle connection strings are different than SQL Server connection strings. So, check all appsettings.json files in your solution and replace the connection strings inside them. See the connectionstrings.com for details of Oracle connection string options.

You typically will change the appsettings.json inside the .DbMigrator and .Web projects, but it depends on your solution structure.

Re-Generate the Migrations

The startup template uses Entity Framework Core's Code First Migrations by default. EF Core Migrations depend on the selected DBMS provider. Changing the DBMS provider, may not work with the existing migrations.

  • Delete the Migrations folder under the .EntityFrameworkCore.DbMigrations project and re-build the solution.
  • Run Add-Migration "Initial" on the Package Manager Console window (select the .DbMigrator (or .Web) project as the startup project in the Solution Explorer and select the .EntityFrameworkCore.DbMigrations project as the default project in the Package Manager Console).

This will scaffold a new migration for Oracle.

Run the .DbMigrator project to create the database, apply the changes and seed the initial data.

Run the Application

It is ready. Just run the application and enjoy coding.