/// <summary> /// 对比表结构 /// </summary> /// <returns></returns> public List <TableCompareResult> CompareDBTable() { RefreshContext(); //todo 排除演示数据的表 var source = _sourceRepository.GetDBTables(); var target = _TargetRepository.GetDBTables(); //对象存在,但是DDLSQL不一致 var difList = (from s in source from t in target.Where(t => s.name == t.name && s.type == t.type && s.sql != t.sql) select new Tuple <DbObjectInfo, DbObjectInfo>(s, t)).ToList(); //source存在target不存在存在=>标准库有,目标库没有,属于少的 var lostList = source.Where(t => !target.Any(s => t.name == s.name && t.type == s.type)).ToList(); //target存在source 不存在 =>标准库没有,属于多的 var moreList = target.Where(t => !source.Any(s => t.name == s.name && t.type == s.type)).ToList(); //加入到结果列表 var ResultList = difList.Select( info => new TableCompareResult { SourceInfo = info.Item1, TargetInfo = info.Item1, ErrorType = 1 }) .ToList(); ResultList.AddRange( lostList.Select(info => new TableCompareResult { SourceInfo = info, TargetInfo = null, ErrorType = 2 })); ResultList.AddRange( moreList.Select(info => new TableCompareResult { SourceInfo = null, TargetInfo = info, ErrorType = 3 })); //找出不同的列,并根据列的信息来生成修复语句 BatchGetDifColByTable(ResultList); _difTableList = ResultList; return(ResultList); }