Abp项目模板使用Oracle数据库包括系统权限管理 by dacong
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
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、使用程序包管理器控制台里面输入@H_403_144@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,
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,
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,
ImpersonatorTenantId = c.Decimal(precision: 10,
CustomData = c.String(maxLength: 2000),
},
annotations: new Dictionary<string,object>
{
{ "DynamicFilter_AuditLog_MayHaveTenant","EntityFramework.DynamicFilters.DynamicFilterDefinition" },
})
.PrimaryKey(t => t.Id);
CreateTable(
"ABP.AbpBackgroundJobs",
JobType = c.String(nullable: false,maxLength: 512),
JobArgs = c.String(nullable: false),
TryCount = c.Decimal(nullable: false,precision: 5,
NextTryTime = c.DateTime(nullable: false),
LastTryTime = c.DateTime(),
IsAbandoned = c.Decimal(nullable: false,precision: 1,
Priority = c.Decimal(nullable: false,precision: 3,
CreationTime = c.DateTime(nullable: false),
CreatorUserId = c.Decimal(precision: 19,
})
.PrimaryKey(t => t.Id)
.Index(t => new { t.IsAbandoned,t.NextTryTime });
CreateTable(
"ABP.AbpFeatures",
Name = c.String(nullable: false,maxLength: 128),
Value = c.String(nullable: false,maxLength: 2000),
EditionId = c.Decimal(precision: 10,
Discriminator = c.String(nullable: false,object>
{
{ "DynamicFilter_EditionFeatureSetting_MayHaveTenant",
{ "DynamicFilter_FeatureSetting_MayHaveTenant",
{ "DynamicFilter_TenantFeatureSetting_MayHaveTenant",
})
.PrimaryKey(t => t.Id)
.ForeignKey("ABP.AbpEditions",t => t.EditionId,cascadeDelete: true)
.Index(t => t.EditionId);
CreateTable(
"ABP.AbpEditions",maxLength: 32),
DisplayName = c.String(nullable: false,maxLength: 64),
IsDeleted = c.Decimal(nullable: false,
DeleterUserId = c.Decimal(precision: 19,
DeletionTime = c.DateTime(),
LastModificationTime = c.DateTime(),
LastModifierUserId = c.Decimal(precision: 19,object>
{
{ "DynamicFilter_Edition_SoftDelete",
})
.PrimaryKey(t => t.Id);
CreateTable(
"ABP.AbpLanguages",maxLength: 10),
Icon = c.String(maxLength: 128),
IsDisabled = c.Decimal(nullable: false,object>
{
{ "DynamicFilter_ApplicationLanguage_MayHaveTenant",
{ "DynamicFilter_ApplicationLanguage_SoftDelete",
})
.PrimaryKey(t => t.Id);
CreateTable(
"ABP.AbpLanguageTexts",
LanguageName = c.String(nullable: false,
Source = c.String(nullable: false,
Key = c.String(nullable: false,maxLength: 256),
Value = c.String(nullable: false),object>
{
{ "DynamicFilter_ApplicationLanguageText_MayHaveTenant",
})
.PrimaryKey(t => t.Id);
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.
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.