Example #1
0
        public void UpdateTag(Tag newTag)
        {
            var previous = _tags.Single(x => x.Id == newTag.Id);

            if (previous != null)
            {
                _tags.Remove(previous);
                _tags.Add(newTag);
            }
        }
Example #2
0
        private List <(string tableName, string conString, DatabaseType dbType)> GetTargetTables
            (string absTableName, ReadWriteType opType, string absDbName, object obj = null)
        {
            //获取抽象数据库
            AbstractDatabase db = null;

            if (absDbName.IsNullOrEmpty())
            {
                db = _absDb.Single();
            }
            else
            {
                db = _absDb.Where(x => x.AbsDbName == absDbName).Single();
            }
            if (db == null)
            {
                throw new Exception("请配置抽象数据库");
            }

            //获取抽象数据表
            var absTable = db.Tables.Where(x => x.AbsTableName == absDbName).Single();

            //获取物理表
            List <(string physicTableName, string dataSourceName)> physicTables = null;

            //读操作获取全部表
            if (opType == ReadWriteType.Read)
            {
                physicTables = absTable.PhysicTables;
            }
            else
            {
                //找特定表
                if (!obj.IsNullOrEmpty())
                {
                    var theTable = absTable.FindTable(obj);
                    physicTables = absTable.PhysicTables.Where(x => x.physicTableName == theTable).ToList();
                }
                //所有表
                else
                {
                    physicTables = absTable.PhysicTables;
                }
            }

            //获取数据源
            var dataSources = _dataSource
                              .Where(x => physicTables.Select(y => y.dataSourceName).Contains(x.DataSourceName))
                              .Select(x => new { x.DataSourceName, x.DbType, RandomHelper.Next(x.Dbs.Where(y => y.opType.HasFlag(opType)).ToList()).conString })
                              .ToList();

            var q = from a in physicTables
                    join b in dataSources on a.dataSourceName equals b.DataSourceName
                    select(a.physicTableName, b.conString, b.DbType);

            var resList = q.ToList();

            return(resList);
        }