Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WithTempQuery中使用Select时无法带入变量的BUG #1965

Open
zhaoyuehui123 opened this issue Jan 16, 2025 · 0 comments
Open

WithTempQuery中使用Select时无法带入变量的BUG #1965

zhaoyuehui123 opened this issue Jan 16, 2025 · 0 comments

Comments

@zhaoyuehui123
Copy link

问题描述及重现代码:

WithTempQuery中使用Select时无法带入变量的BUG,@exp_4和@exp_5不能带进去。

var start = 2023;
var end = 2023;
var res = await Db.Value.Select<MemberCoiHistoryModel>()
    .Where(x => x.Date >= start && x.Date < end && x.Type == CoiType.New && x.State == CoiState.平稳)
    .GroupBy(x => x.MemberId)
    .WithTempQuery(x => new
    {
        MemberId = x.Key,
        ScanSum = Db.Value.Select<MemberActionDayCountModel>()
            .Where(y => y.MemberId == x.Key && y.Date >= start && y.Date < end)
            .Sum(y => y.ScanCode)
    })
    .ToAggregateAsync(x => new
    {
        MemberCount = x.Count(),
        ScanSum = x.Sum(x.Key.ScanSum)
    });

生成的sql如下参数:@exp_0=2023
参数:@exp_1=2023
参数:@exp_2=1
参数:@exp_3=平稳
SELECT count(1) as1, sum(a.[ScanSum]) as2
FROM (
    SELECT a.[MemberId], isnull((SELECT sum(y.[ScanCode])
        FROM [scrm_member_action_day_count] y With(NoLock)
        WHERE (y.[MemberId] = a.[MemberId] AND y.[Date] >= @exp_4 AND y.[Date] < @exp_5)), 0) [ScanSum]
    FROM [scrm_member_coi_history] a With(NoLock)
    WHERE (a.[Date] >= @exp_0 AND a.[Date] < @exp_1 AND a.[Type] = @exp_2 AND a.[State] = @exp_3)
    GROUP BY a.[MemberId] ) a

数据库版本

FreeSql.Provider.SqlServer 3.5.103

安装的Nuget包

FreeSql.Provider.SqlServer

.net framework/. net core? 及具体版本

.net 8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant