ABP vNext切換到EF Core Oracle3.1提供程序
刪除Volo.Abp.EntityFrameworkCore.SqlServer包
解決方案中的 .EntityFrameworkCore
項目刪除 Volo.Abp.EntityFrameworkCore.SqlServer 包.。
nuget,設置默認項目:.EntityFrameworkCore
Install-Package Oracle.EntityFrameworkCore -Version 3.19.0-beta1
增加新的擴展類
因ABP沒有封裝Oracle的模塊,需要自己擴展
我在直接在EntityFrameworkCore項目中增加對Oracle數據庫的擴展
using Microsoft.EntityFrameworkCore;
using System;
using System.Collections.Generic;
using System.Text;
using JetBrains.Annotations;
using Volo.Abp.EntityFrameworkCore.DependencyInjection;
using Oracle.EntityFrameworkCore.Infrastructure;
using Volo.Abp.EntityFrameworkCore;
namespace Admin.EntityFrameworkCore
{
public static class AbpDbContextConfigurationContextOracleExtensions
{
public static DbContextOptionsBuilder UseOracle(
[NotNull] this AbpDbContextConfigurationContext context,
[CanBeNull] Action<OracleDbContextOptionsBuilder> oracleSQLOptionsAction = null)
{
if (context.ExistingConnection != null)
{
return context.DbContextOptions.UseOracle(context.ExistingConnection, oracleSQLOptionsAction);
}
else
{
return context.DbContextOptions.UseOracle(context.ConnectionString, oracleSQLOptionsAction);
}
}
}
public static class AbpDbContextOptionsMySQLExtensions
{
public static void UseOracle(
[NotNull] this AbpDbContextOptions options,
[CanBeNull] Action<OracleDbContextOptionsBuilder> oracleSQLOptionsAction = null)
{
options.Configure(context =>
{
context.UseOracle(oracleSQLOptionsAction);
});
}
public static void UseMySQL<TDbContext>(
[NotNull] this AbpDbContextOptions options,
[CanBeNull] Action<OracleDbContextOptionsBuilder> oracleSQLOptionsAction = null)
where TDbContext : AbpDbContext<TDbContext>
{
options.Configure<TDbContext>(context =>
{
context.UseOracle(oracleSQLOptionsAction);
});
}
}
}
//xxxxxxEntityFrameworkCoreModule.cs文件
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAbpDbContext<SysAdminDbContext>(options =>
{
/* Remove "includeAllEntities: true" to create
* default repositories only for aggregate roots */
options.AddDefaultRepositories(includeAllEntities: true);
});
Configure<AbpDbContextOptions>(options =>
{
/* The main point to change your DBMS.
* See also SysAdminMigrationsDbContextFactory for EF Core tooling. */
options.UseOracle(b => b.UseOracleSQLCompatibility("11"));
});
}
查找你的解決方案中 UseSqlServer()
調用,替換爲 UseOracle()
更改連接字符串
"ConnectionStrings": {
"Default": "DATA SOURCE=LOCALHOST:1521/ORACLE1;USER ID=sys ;PASSWORD=123;Persist Security Info=True;"
}
通常需要更改 .DbMigrator
和 .Web
項目裏面的 appsettings.json
,但它取決於你的解決方案結構.
重新生成遷移
- 刪除
.EntityFrameworkCore.DbMigrations
項目下的Migrations文件夾,並重新生成解決方案. - 在包管理控制檯中運行
Add-Migration "Initial"
(在解決方案資源管理器選擇.DbMigrator
(或.Web
) 做爲啓動項目並且選擇.EntityFrameworkCore.DbMigrations
做爲默認項目). - 需要手工在Oracle數據庫中建立用戶。
這將創建一個配置所有數據庫對象(表)的數據庫遷移.
運行 .DbMigrator
項目創建數據庫和初始種子數據.
運行應用程序
IdentityServer、Host、Web項目。
abp2.8版本,oracle11g數據庫,.net core 3.1 測試成功。