示例#1
0
        /// <summary>
        /// 模型配置重写
        /// </summary>
        /// <param name="modelBuilder">数据实体生成器</param>
        protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
        {
            //兼容oracle,需要设置默认schema
            if (this.Database.Connection.GetType().Name.Equals("OracleConnection"))
            {
                string schema = Regex.Match(this.Database.Connection.ConnectionString, @"[User Id,uid]=([^;]+)").Groups[1].Value;
                modelBuilder.HasDefaultSchema(schema);
            }
            // 禁用一对多级联删除
            modelBuilder.Conventions.Remove <OneToManyCascadeDeleteConvention>();
            // 禁用多对多级联删除
            modelBuilder.Conventions.Remove <ManyToManyCascadeDeleteConvention>();
            // 禁用表名自动复数规则
            modelBuilder.Conventions.Remove <PluralizingTableNameConvention>();

            ConfigurationFactory.ConfigurationsInit(modelBuilder.Configurations);
        }