doc/WebSite/EF-Core-Oracle-Integration.md
Download the starter template with ASP.NET Core and Entity Framework Core to integrate Oracle. Multi-page template with ASP.NET Core + .NET Core Framework + Authentication will be explained in this document.
Install the Oracle.EntityFrameworkCore NuGet package to the *.EntityFrameworkCore project.
Delete Microsoft.EntityFrameworkCore.SqlServer from *.EntityFrameworkCore project because it will not be used anymore.
Some configuration and workarounds are needed to use Oracle with ASP.NET Core and Entity Framework Core.
Replace YourProjectNameDbContextConfigurer.cs with the following lines
public static class PostgreSqlDemoDbContextConfigurer
{
public static void Configure(DbContextOptionsBuilder<PostgreSqlDemoDbContext> builder, string connectionString)
{
builder.UseOracle(connectionString);
}
public static void Configure(DbContextOptionsBuilder<PostgreSqlDemoDbContext> builder, DbConnection connection)
{
builder.UseOracle(connection);
}
}
Change the connection string to your PostgreSQL connection in *.Web.Mvc/appsettings.json and *.Migrator/appsettings.json projects. For example:
{
"ConnectionStrings": {
"Default": "Data Source = (DESCRIPTION = (ADDRESS_LIST = (ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = XE))); User Id = system; Password = 123qwe;"
},
...
}
In order to use Oracle with EF Core, IsolationLevel of the UnitOfWork must be set to ReadCommitted as shown below. You can do this in the PreInitialize method of the Core module of your app.
Configuration.UnitOfWork.IsolationLevel = IsolationLevel.ReadCommitted;
Remove all migration classes(including DbContextModelSnapshot) under *.EntityFrameworkCore/Migrations folder.
because Oracle.EntityFrameworkCore will add some of its own configuration to work with Entity Framework Core.
Now it's ready to build database.
dotnet ef migrations add Initial_Migration command.Configuration.UnitOfWork.IsTransactional = false;
The Oracle integration is now complete. You can now run your project with Oracle.