GroupByModelToSql.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Text.RegularExpressions;
  5. using System.Linq;
  6. using System.Runtime.CompilerServices;
  7. namespace SqlSugar
  8. {
  9. public abstract partial class SqlBuilderProvider : SqlBuilderAccessory, ISqlBuilder
  10. {
  11. public KeyValuePair<string, SugarParameter[]> GroupByModelToSql(List<GroupByModel> models)
  12. {
  13. StringBuilder sql = new StringBuilder("");
  14. var pars = new List<SugarParameter> { };
  15. foreach (var item in models)
  16. {
  17. if (item is GroupByModel && item.FieldName is IFuncModel)
  18. {
  19. var orderByModel = item as GroupByModel;
  20. sql.Append($" {GetSqlPart(item.FieldName, pars)} ,");
  21. }
  22. else if (item is GroupByModel)
  23. {
  24. var orderByModel = item as GroupByModel;
  25. sql.Append($" {this.GetTranslationColumnName(orderByModel.FieldName.ObjToString().ToSqlFilter())} ,");
  26. }
  27. else
  28. {
  29. }
  30. }
  31. return new KeyValuePair<string, SugarParameter[]>(sql.ToString().TrimEnd(','), pars?.ToArray());
  32. }
  33. }
  34. }