Exemplo n.º 1
0
        /// <summary>
        ///     找出不同的列,并根据列的信息来生成修复语句
        /// </summary>
        /// <param name="info"></param>
        public void BatchGetDifColByTable(List <TableCompareResult> tableInfos)
        {
            var difinfo = tableInfos.Where(x => x.ErrorType == 1).ToList();

            if (!difinfo.Any())
            {
                return;
            }
            foreach (var info in difinfo)
            {
                var sourcecol = _sourceRepository.GetColInfoByTable(info.SourceInfo.name).ToList();
                var targetcol = _TargetRepository.GetColInfoByTable(info.TargetInfo.name).ToList();

                if (!(sourcecol != null && targetcol != null))
                {
                    continue;
                }


                var lostList = new List <SqliteColInfo>();
                var moreList = new List <SqliteColInfo>();

                /*
                 * //对象存在,但是DDLSQL不一致
                 * //目前咱不考虑列的其他信息不一致的情况,这种情况建议是删掉重新建,但是客户数据又不要处理,所以暂不考虑
                 * var difList = (from s in sourcecol
                 *  from t in
                 *      targetcol.Where(
                 *          t =>
                 *              s.name == t.name &&
                 *              (s.type != t.type || s.NotNull != t.NotNull || s.Dflt_Value != t.Dflt_Value ||
                 *               s.Pk != t.typePk))
                 *  select new Tuple<SqliteColInfo, SqliteColInfo>(s, t)).ToList();
                 * //先删后建
                 * foreach (var dif in difList)
                 * {
                 *  moreList.Add(dif.Item1);
                 *  lostList.Add(dif.Item2);
                 * }*/
                //source存在target不存在存在=>标准库有,目标库没有,属于少的
                lostList.AddRange(sourcecol.Where(t => targetcol.All(s => t.Name != s.Name)));
                //target存在source 不存在  =>标准库没有,属于多的
                moreList.AddRange(targetcol.Where(t => sourcecol.All(s => t.Name != s.Name)));

                info.SourceCol = sourcecol;
                info.TargetCol = targetcol;

                info.LostCol = lostList;
                info.MoreCol = moreList;
            }
        }