コード例 #1
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.AddPropertyValueConversion();
            var tenantId     = GetTenantId();
            var timeZoneName = GetTimeZoneName();

            if (tenantId != 0)
            {
                modelBuilder.AddTenantFilter <int>(tenantId);
            }
            if (!string.IsNullOrEmpty(timeZoneName))
            {
                modelBuilder.AddTimeZoneValueConversion(timeZoneName);
            }
            if (DatabaseConfig.MultiTenant.SchemaBasedMultiTenant)
            {
                var schemaInfo = TenantDbConnection.GetAsync(this.ContextAccessor.HttpContext.Request.Host.Value).Result;
                if (schemaInfo != null && schemaInfo.Keys.Contains(DbContext.Name))
                {
                    modelBuilder.AddSchemaBasedTenant(schemaInfo[DbContext.Name]);
                }
            }
            modelBuilder.GlobalQueryFilter();
            //modelBuilder.Entity(typeof(vUser)).HasQueryFilter(Expression());
        }
コード例 #2
0
ファイル: BaseContext.cs プロジェクト: vive-there/RxWebCore
        private string GetDbConnectionString(string keyName)
        {
            var connectionString = string.Empty;

            if (ConnectionStringConfig.ContainsKey(keyName) && !string.IsNullOrEmpty(ConnectionStringConfig[keyName]))
            {
                connectionString = ConnectionStringConfig[keyName];
            }
            else
            {
                var hostUri = GetHostUri();
                if (DatabaseConfig.MultiTenant != null && DatabaseConfig.MultiTenant.Database != null && (DatabaseConfig.MultiTenant.Database.ConfigFromDb || DatabaseConfig.MultiTenant.Database.HostUriConnectionMappings.Count > 0))
                {
                    var clientConfig = new Dictionary <string, string>();
                    if (DatabaseConfig.MultiTenant.Database.HostUriConnectionMappings.Count > 0 && DatabaseConfig.MultiTenant.Database.HostUriConnectionMappings.ContainsKey(hostUri))
                    {
                        clientConfig = DatabaseConfig.MultiTenant.Database.HostUriConnectionMappings[hostUri];
                    }
                    else
                    {
                        clientConfig = TenantDbConnection.GetAsync(hostUri).Result;
                    }
                    if (clientConfig != null && clientConfig.ContainsKey(keyName))
                    {
                        connectionString = clientConfig[keyName];
                    }
                }
            }
            return(connectionString);
        }
コード例 #3
0
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.AddPropertyValueConversion();
            modelBuilder.AddCompositeKeys();
            var tenantId     = GetTenantId();
            var timeZoneName = GetTimeZoneName();

            if (tenantId != 0)
            {
                modelBuilder.AddTenantFilter <int>(tenantId);
            }
            if (!string.IsNullOrEmpty(timeZoneName))
            {
                modelBuilder.AddTimeZoneValueConversion(timeZoneName);
            }
            if (DatabaseConfig.MultiTenant.Schema != null && (DatabaseConfig.MultiTenant.Schema.ConfigFromDb || DatabaseConfig.MultiTenant.Schema.HostUriSchemaMappings.Count > 0))
            {
                var schemaInfo = new Dictionary <string, string>();
                var hostUri    = this.ContextAccessor.HttpContext.Request.Host.Value;
                if (DatabaseConfig.MultiTenant.Schema.ConfigFromDb)
                {
                    schemaInfo = TenantDbConnection.GetAsync(hostUri).Result;
                }
                else if (DatabaseConfig.MultiTenant.Schema.HostUriSchemaMappings.ContainsKey(hostUri))
                {
                    schemaInfo = DatabaseConfig.MultiTenant.Schema.HostUriSchemaMappings[hostUri];
                }
                if (schemaInfo != null && schemaInfo.Keys.Contains(DbContext.Name))
                {
                    modelBuilder.AddSchemaBasedTenant(schemaInfo[DbContext.Name]);
                }
            }
            modelBuilder.GlobalQueryFilter();
        }
コード例 #4
0
ファイル: BaseContext.cs プロジェクト: sukhdev22/RxWebCore
        private string GetDbConnectionString(string keyName)
        {
            var connectionString = string.Empty;

            if (ConnectionStringConfig.ContainsKey(keyName) && !string.IsNullOrEmpty(ConnectionStringConfig[keyName]))
            {
                connectionString = ConnectionStringConfig[keyName];
            }
            else
            {
                var hostUri      = GetHostUri();
                var clientConfig = TenantDbConnection.GetAsync(hostUri).Result;
                if (clientConfig != null && clientConfig.ContainsKey(keyName))
                {
                    connectionString = clientConfig[keyName];
                }
            }
            return(connectionString);
        }
コード例 #5
0
        private string GetDbConnectionString(string keyName)
        {
            var connectionString = string.Empty;

            if (ConnectionStringConfig.ContainsKey(keyName) && !string.IsNullOrEmpty(ConnectionStringConfig[keyName]))
            {
                connectionString = ConnectionStringConfig[keyName];
            }
            else
            {
                var clientId = GetClaimValue(ApplicationConstants.X_CLIENT);
                if (clientId != 0)
                {
                    var clientConfig = TenantDbConnection.Get(clientId);
                    if (clientConfig != null && clientConfig.ContainsKey(keyName))
                    {
                        connectionString = clientConfig[keyName];
                    }
                }
            }
            return(connectionString);
        }