/// <summary> /// 构建Select语句 /// </summary> /// <param name="columns"></param> /// <returns></returns> private string SelectBuild(string columns = "*") { columns = columns == "*" ? string.Join(",", TypeMapper.GetDbColumn <T>().Select(s => string.Format("{0} AS {1}", s.ColumnName, s.FieldName))) : columns; columns = (_distinct != null ? _distinct + " " : "") + columns; QuerySql.AppendFormat("SELECT {0} FROM {1}", columns, FromSql); if (_where.Length > 0) { QuerySql.AppendFormat(" WHERE {0}", _where); } if (_groupBy.Length > 0) { QuerySql.AppendFormat(" GROUP BY {0}", _groupBy); } if (_having.Length > 0) { QuerySql.AppendFormat(" HAVING {0}", _having); } if (_orderBy.Length > 0) { QuerySql.AppendFormat(" ORDER BY {0}", _orderBy); } if (_limit.Length > 0) { QuerySql.AppendFormat(" LIMIT {0}", _limit); } if (_lock.Length > 0) { QuerySql.AppendFormat(" {0}", _lock); } return(QuerySql.ToString()); }
private string UpdateBuild(bool condition) { if (_set.Length > 0) { UpdateSql.AppendFormat("UPDATE {0}", FromSql); UpdateSql.AppendFormat(" SET {0}", _set); } else { var colums = TypeMapper.GetDbColumn <T>(); UpdateSql.AppendFormat("UPDATE {0} SET {1}", FromSql, string.Join(",", colums.FindAll(f => f.PrimaryKey == false).Select(s => s.ColumnName + " = @" + s.FieldName))); } if (condition) { UpdateSql.AppendFormat(" WHERE {0} = @{0}", TypeMapper.GetIdentityFieldName <T>()); } else if (_where.Length > 0) { UpdateSql.AppendFormat(" WHERE {0}", _where); } return(UpdateSql.ToString()); }