Abp项目模板使用Oracle数据库包括系统权限管理
2017-12-10 04:06
831 查看
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<Tenant, Role, User>
{
//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<NotificationInfo>().Property(e => e.EntityTypeAssemblyQualifiedName).HasColumnName("EntityTypeAssemblyQn");
modelBuilder.Entity<NotificationSubscriptionInfo>().Property(e => e.EntityTypeAssemblyQualifiedName).HasColumnName("EntityTypeAssemblyQn");
modelBuilder.Entity<TenantNotificationInfo>().Property(e => e.EntityTypeAssemblyQualifiedName).HasColumnName("EntityTypeAssemblyQn");
}
public class MESDataModule : AbpModule
{
public override void PreInitialize()
{
//Database.SetInitializer(new CreateDatabaseIfNotExists<MESDbContext>());
Configuration.UnitOfWork.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;//ORA-08177
Configuration.DefaultNameOrConnectionString = "Default";
}
public override void Initialize()
{
IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
Database.SetInitializer<MESDbContext>(null);
}
}
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<string, object>
{
{ "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<string, object>
{
{ "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<string, object>
{
{ "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<string, object>
{
{ "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<string, object>
{
{ "DynamicFilter_ApplicationLanguageText_MayHaveTenant", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
})
.PrimaryKey(t => t.Id);
。。。。。。省略,这个cs或生成Oracle的表的。
7、 update-database
无红色错误,为成功。
PM> update-database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Applying explicit migrations: [201712091925426_abp_init].
Applying explicit migration: 201712091925426_abp_init.
Running Seed method.
查看Oracle数据库,有如下的表,AbpUsers已经包含admin用户
__MigrationHistory
AbpAuditLogs
AbpBackgroundJobs
AbpEditions
AbpFeatures
AbpLanguages
AbpLanguageTexts
AbpNotifications
AbpNotificationSubscriptions
AbpOrganizationUnits
AbpPermissions
AbpRoles
AbpSettings
AbpTenantNotifications
AbpTenants
AbpUserAccounts
AbpUserClaims
AbpUserLoginAttempts
AbpUserLogins
AbpUserNotifications
AbpUserOrganizationUnits
AbpUserRoles
AbpUsers
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.
参考: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<Tenant, Role, User>
{
//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<NotificationInfo>().Property(e => e.EntityTypeAssemblyQualifiedName).HasColumnName("EntityTypeAssemblyQn");
modelBuilder.Entity<NotificationSubscriptionInfo>().Property(e => e.EntityTypeAssemblyQualifiedName).HasColumnName("EntityTypeAssemblyQn");
modelBuilder.Entity<TenantNotificationInfo>().Property(e => e.EntityTypeAssemblyQualifiedName).HasColumnName("EntityTypeAssemblyQn");
}
public class MESDataModule : AbpModule
{
public override void PreInitialize()
{
//Database.SetInitializer(new CreateDatabaseIfNotExists<MESDbContext>());
Configuration.UnitOfWork.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;//ORA-08177
Configuration.DefaultNameOrConnectionString = "Default";
}
public override void Initialize()
{
IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
Database.SetInitializer<MESDbContext>(null);
}
}
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<string, object>
{
{ "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<string, object>
{
{ "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<string, object>
{
{ "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<string, object>
{
{ "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<string, object>
{
{ "DynamicFilter_ApplicationLanguageText_MayHaveTenant", "EntityFramework.DynamicFilters.DynamicFilterDefinition" },
})
.PrimaryKey(t => t.Id);
。。。。。。省略,这个cs或生成Oracle的表的。
7、 update-database
无红色错误,为成功。
PM> update-database
Specify the '-Verbose' flag to view the SQL statements being applied to the target database.
Applying explicit migrations: [201712091925426_abp_init].
Applying explicit migration: 201712091925426_abp_init.
Running Seed method.
查看Oracle数据库,有如下的表,AbpUsers已经包含admin用户
__MigrationHistory
AbpAuditLogs
AbpBackgroundJobs
AbpEditions
AbpFeatures
AbpLanguages
AbpLanguageTexts
AbpNotifications
AbpNotificationSubscriptions
AbpOrganizationUnits
AbpPermissions
AbpRoles
AbpSettings
AbpTenantNotifications
AbpTenants
AbpUserAccounts
AbpUserClaims
AbpUserLoginAttempts
AbpUserLogins
AbpUserNotifications
AbpUserOrganizationUnits
AbpUserRoles
AbpUsers
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.
相关文章推荐
- ABP+AdminLTE+Bootstrap Table权限管理系统第一节--使用ASP.NET Boilerplate模板创建解决方案
- ABP+AdminLTE+Bootstrap Table权限管理系统第一节--使用ASP.NET Boilerplate模板创建解决方案
- 使用.net core ABP和Angular模板构建博客管理系统(完善前台服务)
- JavaWeb企业实训 简易股市自选查询分析系统(六)使用Shiro控制登录等权限管理与Spring项目整合
- ABP+AdminLTE+Bootstrap Table权限管理系统第十节--AdminLTE模板菜单处理
- 使用.net core ABP和Angular模板构建博客管理系统(实现自己的业务逻辑)
- 在前后端分离的项目中,后台使用shiro框架时,怎样使用它的会话管理系统(session),从而实现权限控制
- 使用.net core ABP和Angular模板构建博客管理系统(实现编辑页面功能)
- ABP module-zero +AdminLTE+Bootstrap Table+jQuery权限管理系统第十五节--缓存小结与ABP框架项目中 Redis Cache的实现
- ABP+AdminLTE+Bootstrap Table权限管理系统第九节--AdminLTE引入及模板页和布局和菜单
- [ABP开源项目]--vue+vuex+vue-router+EF的权限管理系统
- Asp.Net Core 项目实战之权限管理系统(3) 通过EntityFramework Core使用PostgreSQL
- 使用.net core ABP和Angular模板构建博客管理系统(实现博客列表页面)
- Asp.Net Core 项目实战之权限管理系统(1) 使用AdminLTE搭建前端
- ABP module-zero +AdminLTE+Bootstrap Table+jQuery权限管理系统第十五节--缓存小结与ABP框架项目中 Redis Cache的实现
- 使用.net core ABP和Angular模板构建博客管理系统(创建后端服务)
- C# ASP.NET 走火入魔通用权限管理系统组件V3.2试用版下载地址【含数据库设计文档、使用手册】
- 通用权限管理系统使用说明——具体
- 使用django的权限管理系统permission
- 通用权限管理系统使用说明——具体