mirror of
https://github.com/dotnetcore/FreeSql.git
synced 2026-02-06 00:10:55 +08:00
- 修复 ISelectGroupingAggregate 自定义解析方法报错的问题;
This commit is contained in:
@@ -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<OrderLine, Product>()
|
||||
.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<MemberActionDayCountModel>()
|
||||
.Where(x => x.Date >= 20230101 && x.Date < 20240101 && x.ScanCode > 0)
|
||||
.Where(x =>
|
||||
@@ -3511,3 +3524,13 @@ public sealed class MemberActionDayCountModel
|
||||
public decimal ScanCodeAmount { get; set; }
|
||||
#endregion
|
||||
}
|
||||
[ExpressionCall]
|
||||
public static class ExpressionCallExtesions
|
||||
{
|
||||
static ThreadLocal<ExpressionCallContext> context = new ThreadLocal<ExpressionCallContext>();
|
||||
public static int CountDistinct<TKey, TValue>(this ISelectGroupingAggregate<TKey, TValue> that, object column)
|
||||
{
|
||||
context.Value.Result = $"count(distinct {context.Value.ParsedContent["column"]})";
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user