diff --git a/Examples/base_entity/Program.cs b/Examples/base_entity/Program.cs index ab4f15a69..6e06396d5 100644 --- a/Examples/base_entity/Program.cs +++ b/Examples/base_entity/Program.cs @@ -13,6 +13,7 @@ using NetTopologySuite.Geometries; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using Npgsql; +using Org.BouncyCastle.Tls; using System; using System.Collections; using System.Collections.Concurrent; @@ -620,6 +621,18 @@ namespace base_entity BaseEntity.Initialization(fsql, () => _asyncUow.Value); #endregion + var sql20250205 = fsql.Select() + .InnerJoin((l, p) => l.ProductId == p.ID) + .GroupBy((l, p) => new { p.ID, ShopType = l.ShopType ?? 0 }) + .ToSql(x => new + { + TradeId = x.Key.ID, + ShopType = x.Key.ShopType, + FieldCount = x.CountDistinct(x.Value.Item2.ID), + Count = x.Count(x.Value.Item1.Id), + Kb = (long)x.Sum(x.Value.Item1.Amount) + }); + var res = fsql.Select() .Where(x => x.Date >= 20230101 && x.Date < 20240101 && x.ScanCode > 0) .Where(x => @@ -3510,4 +3523,14 @@ public sealed class MemberActionDayCountModel /// public decimal ScanCodeAmount { get; set; } #endregion +} +[ExpressionCall] +public static class ExpressionCallExtesions +{ + static ThreadLocal context = new ThreadLocal(); + public static int CountDistinct(this ISelectGroupingAggregate that, object column) + { + context.Value.Result = $"count(distinct {context.Value.ParsedContent["column"]})"; + return 0; + } } \ No newline at end of file diff --git a/FreeSql/Internal/CommonExpression.cs b/FreeSql/Internal/CommonExpression.cs index 3f2e98b40..d193663b2 100644 --- a/FreeSql/Internal/CommonExpression.cs +++ b/FreeSql/Internal/CommonExpression.cs @@ -2055,6 +2055,7 @@ namespace FreeSql.Internal { var expStackFirst = expStack.First() as ParameterExpression; var bidx = expStackFirst.Type.FullName.StartsWith("FreeSql.ISelectGroupingAggregate`") ? 2 : 1; //.Key .Value + if (bidx == 2 && expStack.Count == 1) return ""; //不解析 var diyexpMembers = expStack.Where((a, b) => b >= bidx).ToArray(); if (diyexpMembers.Any() == false && diymemexp != null && diymemexp is Select0Provider.WithTempQueryParser tempQueryParser && tempQueryParser.GetOutsideSelectTable(expStackFirst) != null) diyexpMembers = expStack.ToArray();