/// <summary> /// 此处去掉主键,即插入操作不能操作id /// </summary> /// <param name="tuple"></param> /// <returns></returns> private String GetInsertSql(Tuple <List <String>, List <String> > tuple) { String pk = EntityTableMapper.GetPkColumn(typeof(T)); StringBuilder colstr = new StringBuilder(); StringBuilder valstr = new StringBuilder(); List <String> cols = tuple.Item1; List <String> props = tuple.Item2; for (Int32 i = 0; i < cols.Count; i++) { //去掉主键 if (cols[i] == pk) { continue; } if (colstr.Length != 0) { colstr.Append(","); valstr.Append(","); } colstr.Append(cols[i]); valstr.Append($"@{props[i]}"); } return($"({colstr.ToString()}) values ({valstr.ToString()})"); }
private String GetUpdateSql(Tuple <List <String>, List <String> > tuple) { String pk = EntityTableMapper.GetPkColumn(typeof(T)); StringBuilder colstr = new StringBuilder(); List <String> cols = tuple.Item1; List <String> props = tuple.Item2; for (Int32 i = 0; i < cols.Count; i++) { //去掉主键 if (cols[i] == pk) { continue; } if (colstr.Length != 0) { colstr.Append(","); } // synctimes = synctimes+1 的形式便直接拼接 //注意,此处在解析header时候,便是1:1的关系,如果是set中便是为空 if (String.IsNullOrEmpty(props[i])) { colstr.Append($" {cols[i]} "); } else { colstr.Append($"{cols[i]} = @{props[i]}"); } } return(colstr.ToString()); }
private void SetNoneWhere(Type t) { String pk = EntityTableMapper.GetPkColumn(t); if (String.IsNullOrEmpty(pk)) { throw new ArgumentException("请使用带主键的或者添加删选条件"); } String pkValue = ValuePairs[pk].ColumnName; ColumnRelevanceMapper column = new ColumnRelevanceMapper(); column.ColumnName = pk; column.TableName = t; ColumnRelevanceMapper value = new ColumnRelevanceMapper(); value.ColumnName = pk; value.SqlOperatorEnum = SqlOperatorEnum.Equal; Reduce.AddWhere(column); Reduce.AddWhere(value); }