Update json 2 sql

This commit is contained in:
sunkaixuan
2023-12-06 14:32:36 +08:00
parent a35f8b164d
commit f2191431e2
2 changed files with 11 additions and 5 deletions

View File

@@ -7,7 +7,7 @@ namespace SqlSugar
{ {
public class GroupByModel public class GroupByModel
{ {
public string FieldName { get; set; } public object FieldName { get; set; }
public static List<GroupByModel> Create(params GroupByModel[] groupModels) public static List<GroupByModel> Create(params GroupByModel[] groupModels)
{ {
return groupModels.ToList(); return groupModels.ToList();

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices;
namespace SqlSugar namespace SqlSugar
{ {
public abstract partial class SqlBuilderProvider : SqlBuilderAccessory, ISqlBuilder public abstract partial class SqlBuilderProvider : SqlBuilderAccessory, ISqlBuilder
@@ -10,13 +11,18 @@ namespace SqlSugar
public KeyValuePair<string, SugarParameter[]> GroupByModelToSql(List<GroupByModel> models) public KeyValuePair<string, SugarParameter[]> GroupByModelToSql(List<GroupByModel> models)
{ {
StringBuilder sql = new StringBuilder(""); StringBuilder sql = new StringBuilder("");
SugarParameter[] pars = new SugarParameter[] { }; var pars = new List<SugarParameter> { };
foreach (var item in models) foreach (var item in models)
{ {
if (item is GroupByModel) if (item is GroupByModel && item.FieldName is IFuncModel)
{ {
var orderByModel = item as GroupByModel; var orderByModel = item as GroupByModel;
sql.Append($" {this.GetTranslationColumnName(orderByModel.FieldName.ToSqlFilter())} ,"); sql.Append($" {GetSqlPart(item.FieldName, pars)} ,");
}
else if (item is GroupByModel)
{
var orderByModel = item as GroupByModel;
sql.Append($" {this.GetTranslationColumnName(orderByModel.FieldName.ObjToString().ToSqlFilter())} ,");
} }
else else
{ {
@@ -24,7 +30,7 @@ namespace SqlSugar
} }
} }
return new KeyValuePair<string, SugarParameter[]>(sql.ToString().TrimEnd(','), pars); return new KeyValuePair<string, SugarParameter[]>(sql.ToString().TrimEnd(','), pars?.ToArray());
} }
} }
} }