解决方案中的 .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
{
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
{
options.Configure(context =>
{
context.UseOracle(oracleSQLOptionsAction);
});
}
public static void UseMySQL
[NotNull] this AbpDbContextOptions options,
[CanBeNull] Action
where TDbContext : AbpDbContext
{
options.Configure
{
context.UseOracle(oracleSQLOptionsAction);
});
}
}
}
//xxxxxxEntityFrameworkCoreModule.cs文件
public override void ConfigureServices(ServiceConfigurationContext context)
{
context.Services.AddAbpDbContext
{
/* Remove "includeAllEntities: true" to create
* default repositories only for aggregate roots */
options.AddDefaultRepositories(includeAllEntities: true);
});
Configure
{
/* 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
做为默认项目).这将创建一个配置所有数据库对象(表)的数据库迁移.
运行 .DbMigrator
项目创建数据库和初始种子数据.
IdentityServer、Host、Web项目。
abp2.8版本,oracle11g数据库,.net core 3.1 测试成功。