Abp项目模板使用Oracle数据库包括系统权限管理

来源:互联网 发布:推广淘宝优惠券赚钱 编辑:程序博客网 时间:2024/06/05 12:05

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.
  

阅读全文
0 0
原创粉丝点击