コード例 #1
0
        public IConfigInit AddPhysicTable <TEntity>(string physicTableName, string groupName = "BaseDbGroup")
        {
            var absEntityType = typeof(TEntity);

            _lock.EnterReadLock();
            bool exists = _physicTables.Any(x =>
                                            x.AbsTableName == absEntityType.Name &&
                                            x.GroupName == groupName &&
                                            x.PhysicTableName == physicTableName);

            _lock.ExitReadLock();
            if (exists)
            {
                return(this);
            }

            _lock.EnterWriteLock();
            _physicTables.Add(new PhysicTable
            {
                AbsTableName    = absEntityType.Name,
                GroupName       = groupName,
                PhysicTableName = physicTableName
            });
            _lock.ExitWriteLock();

            var physicEntityType = ShardingHelper.MapTable(absEntityType, physicTableName);

            DbModelFactory.AddEntityType(physicTableName, physicEntityType);

            return(this);
        }
コード例 #2
0
        public List <(string tableName, string conString, DatabaseType dbType)> GetReadTables(string absTableName, string absDbName, IQueryable source)
        {
            var rule          = GetShardingRule(absDbName, absTableName);
            var allTables     = GetTargetTables(absTableName, ReadWriteType.Read, absDbName);
            var allTableNames = allTables.Select(x => x.tableName).ToList();
            var findTables    = ShardingHelper.FilterTable(source, allTableNames, rule);

            allTables = allTables.Where(x => findTables.Contains(x.tableName)).ToList();
#if DEBUG
            Console.WriteLine($"查询分表:{string.Join(",", findTables)}");
#endif
            return(allTables);
        }