Abp项目模板使用Oracle数据库包括系统权限管理 by dacong
参考:Abp项目的创建以及Oracle的支持
aspnet-zero-core 使用MySql数据库 http://www.sohu.com/a/162365978_468635
abp项目是可以支持任何数据库的,需要数据库支持entityframework可以无缝移植。
测试环境:oracle11g,abp 3.2.5,vs2017
Abp项目使用Oracle数据库,支持module zero。支持所有用户管理、权限管理、角色管理等。
1、建立项目的时候选择"module zero",
2、添加Oracle.ManagedDataAccess.EntityFramework包从nuget
3、配合app.config,保证oracle的连接正常
4、删除Migrations 目录已日期开头的.cs文件,如201707261347311_Initial_Migration.cs,201710131316266_UpgradedTo_ABP_3.1.cs
5、修改如下文件:
public class MESDbContext : AbpZeroDbContext
{
//TODO: Define an IDbSet for your Entities...
/* NOTE:
* Setting "Default" to base class helps us when working migration commands on Package Manager Console.
* But it may cause problems when working Migrate.exe of EF. If you will apply migrations on command line, do not
* pass connection string name to base classes. ABP works either way. by dacong
*/
public MESDbContext()
: base("Default")
{
//Default要与app.config的一致,把oracle自动配置的OracleContext改成default
}
/* NOTE:
* This constructor is used by ABP to pass connection string defined in MESDataModule.PreInitialize.
* Notice that, actually you will not directly create an instance of MESDbContext since ABP automatically handles it.
*/
public MESDbContext(string nameOrConnectionString)
: base(nameOrConnectionString)
{
}
//This constructor is used in tests
public MESDbContext(DbConnection existingConnection)
: base(existingConnection, false)
{
}
public MESDbContext(DbConnection existingConnection, bool contextOwnsConnection)
: base(existingConnection, contextOwnsConnection)
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("ABP");
base.OnModelCreating(modelBuilder);
//EntityTypeAssemblyQualifiedName字段过长
modelBuilder.Entity
modelBuilder.Entity
modelBuilder.Entity
}
public class MESDataModule : AbpModule
{
public override void PreInitialize()
{
//Database.SetInitializer(new CreateDatabaseIfNotExists
Configuration.UnitOfWork.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;//ORA-08177
Configuration.DefaultNameOrConnectionString = "Default";
}
public override void Initialize()
{
IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
Database.SetInitializer
}
}
6、使用程序包管理器控制台里面输入 Add-Migration init
会生成移植文件,如下
public partial class abp_init : DbMigration
{
public override void Up()
{
CreateTable(
"ABP.AbpAuditLogs",
c => new
{
Id = c.Decimal(nullable: false, precision: 19, scale: 0, identity: true),
TenantId = c.Decimal(precision: 10, scale: 0),
UserId = c.Decimal(precision: 19, scale: 0),
ServiceName = c.String(maxLength: 256),
MethodName = c.String(maxLength: 256),
Parameters = c.String(maxLength: 1024),
ExecutionTime = c.DateTime(nullable: false),
ExecutionDuration = c.Decimal(nullable: false, precision: 10, scale: 0),
ClientIpAddress = c.String(maxLength: 64),
ClientName = c.String(maxLength: 128),
BrowserInfo = c.String(maxLength: 256),
Exception = c.String(maxLength: 2000),
ImpersonatorUserId = c.Decimal(precision: 19, scale: 0),
ImpersonatorTenantId = c.Decimal(precision: 10, scale: 0),
CustomData = c.String(maxLength: 2000),
},
annotations: new Dictionary
{
{ "DynamicFilter_AuditLog_MayHaveTenant", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
})
.PrimaryKey(t => t.Id);
CreateTable(
"ABP.AbpBackgroundJobs",
c => new
{
Id = c.Decimal(nullable: false, precision: 19, scale: 0, identity: true),
JobType = c.String(nullable: false, maxLength: 512),
JobArgs = c.String(nullable: false),
TryCount = c.Decimal(nullable: false, precision: 5, scale: 0),
NextTryTime = c.DateTime(nullable: false),
LastTryTime = c.DateTime(),
IsAbandoned = c.Decimal(nullable: false, precision: 1, scale: 0),
Priority = c.Decimal(nullable: false, precision: 3, scale: 0),
CreationTime = c.DateTime(nullable: false),
CreatorUserId = c.Decimal(precision: 19, scale: 0),
})
.PrimaryKey(t => t.Id)
.Index(t => new { t.IsAbandoned, t.NextTryTime });
CreateTable(
"ABP.AbpFeatures",
c => new
{
Id = c.Decimal(nullable: false, precision: 19, scale: 0, identity: true),
TenantId = c.Decimal(precision: 10, scale: 0),
Name = c.String(nullable: false, maxLength: 128),
Value = c.String(nullable: false, maxLength: 2000),
CreationTime = c.DateTime(nullable: false),
CreatorUserId = c.Decimal(precision: 19, scale: 0),
EditionId = c.Decimal(precision: 10, scale: 0),
Discriminator = c.String(nullable: false, maxLength: 128),
},
annotations: new Dictionary
{
{ "DynamicFilter_EditionFeatureSetting_MayHaveTenant", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
{ "DynamicFilter_FeatureSetting_MayHaveTenant", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
{ "DynamicFilter_TenantFeatureSetting_MayHaveTenant", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
})
.PrimaryKey(t => t.Id)
.ForeignKey("ABP.AbpEditions", t => t.EditionId, cascadeDelete: true)
.Index(t => t.EditionId);
CreateTable(
"ABP.AbpEditions",
c => new
{
Id = c.Decimal(nullable: false, precision: 10, scale: 0, identity: true),
Name = c.String(nullable: false, maxLength: 32),
DisplayName = c.String(nullable: false, maxLength: 64),
IsDeleted = c.Decimal(nullable: false, precision: 1, scale: 0),
DeleterUserId = c.Decimal(precision: 19, scale: 0),
DeletionTime = c.DateTime(),
LastModificationTime = c.DateTime(),
LastModifierUserId = c.Decimal(precision: 19, scale: 0),
CreationTime = c.DateTime(nullable: false),
CreatorUserId = c.Decimal(precision: 19, scale: 0),
},
annotations: new Dictionary
{
{ "DynamicFilter_Edition_SoftDelete", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
})
.PrimaryKey(t => t.Id);
CreateTable(
"ABP.AbpLanguages",
c => new
{
Id = c.Decimal(nullable: false, precision: 10, scale: 0, identity: true),
TenantId = c.Decimal(precision: 10, scale: 0),
Name = c.String(nullable: false, maxLength: 10),
DisplayName = c.String(nullable: false, maxLength: 64),
Icon = c.String(maxLength: 128),
IsDisabled = c.Decimal(nullable: false, precision: 1, scale: 0),
IsDeleted = c.Decimal(nullable: false, precision: 1, scale: 0),
DeleterUserId = c.Decimal(precision: 19, scale: 0),
DeletionTime = c.DateTime(),
LastModificationTime = c.DateTime(),
LastModifierUserId = c.Decimal(precision: 19, scale: 0),
CreationTime = c.DateTime(nullable: false),
CreatorUserId = c.Decimal(precision: 19, scale: 0),
},
annotations: new Dictionary
{
{ "DynamicFilter_ApplicationLanguage_MayHaveTenant", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
{ "DynamicFilter_ApplicationLanguage_SoftDelete", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
})
.PrimaryKey(t => t.Id);
CreateTable(
"ABP.AbpLanguageTexts",
c => new
{
Id = c.Decimal(nullable: false, precision: 19, scale: 0, identity: true),
TenantId = c.Decimal(precision: 10, scale: 0),
LanguageName = c.String(nullable: false, maxLength: 10),
Source = c.String(nullable: false, maxLength: 128),
Key = c.String(nullable: false, maxLength: 256),
Value = c.String(nullable: false),
LastModificationTime = c.DateTime(),
LastModifierUserId = c.Decimal(precision: 19, scale: 0),
CreationTime = c.DateTime(nullable: false),
CreatorUserId = c.Decimal(precision: 19, scale: 0),
},
annotations: new Dictionary
{
{ "DynamicFilter_ApplicationLanguageText_MayHaveTenant", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
})
.PrimaryKey(t => t.Id);
8、给web项目也增加racle.ManagedDataAccess.EntityFramework,并修改web.cong。
9、启动web项目。
目前这个版本在web项目第一次启动时或保存,刷新后可以正常使用。
CAC.MES.Web.Controllers.HomeController - An error occurred while preparing the command definition. See the inner exception for details.
System.Data.Entity.Core.EntityCommandCompilationException: An error occurred while preparing the command definition. See the inner exception for details. ---> System.NotSupportedException: A second operation started on this context before a previous asynchronous operation completed. Use 'await' to ensure that any asynchronous operations have completed before calling another method on this context. Any instance members are not guaranteed to be thread safe.