Example #1
0
 /// <summary>
 /// 构建Select语句
 /// </summary>
 /// <param name="columns"></param>
 /// <returns></returns>
 private string SelectBuild(string columns = "*")
 {
     columns = columns == "*" ? string.Join(",", TypeMapper.GetColumns <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());
 }
Example #2
0
 /// <summary>
 /// 构建更新语句
 /// </summary>
 /// <returns></returns>
 public string UpdateBuild(bool condition)
 {
     if (_set.Length > 0)
     {
         UpdateSql.AppendFormat("UPDATE {0}", FromSql);
         UpdateSql.AppendFormat(" SET {0}", _set);
     }
     else
     {
         var colums = TypeMapper.GetColumns <T>();
         UpdateSql.AppendFormat("UPDATE {0} SET {1}", FromSql, string.Join(",", colums.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());
 }