-
Notifications
You must be signed in to change notification settings - Fork 861
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
UseGenerateCommandParameterWithLambda(true)时,使用Where条件+子查询有一定概率出现异常:“必须声明标量变量 "@exp_0" #1155
Comments
类似这样并发测试吗,没有出现上述报错。 static void TestExp(IFreeSql fsql)
{
var tasks = new List<Task>();
for (var a = 0; a < 100; a++)
{
var task = Task.Run(async () =>
{
var name = "123";
var result = await fsql.Select<Rsbasedoc2>()
.Where(t => t.Name == name
&& fsql.Select<Rsbasedoc2>().Any(t2 => t2.Id == t.Id)).ToListAsync();
});
tasks.Add(task);
}
Task.WaitAll(tasks.ToArray());
} |
谢谢反馈描述,找到问题原因了: 1、子查询时,也主查询使用了同一个 List<DbParameter> |
2881099
added a commit
that referenced
this issue
Jun 13, 2022
v3.2.664 重要 bug
|
Closed
WithParameters 参数化共享开启参数化查询功能后,使用 WithParameters 共享参数化,避免产生相同的参数名称: var dbpars = new List<DbParameter>();
var id1 = 1;
var id2 = 2;
var sql = fsql.Select<User1>()
.WithParameters(dbpars)
.Where(a => a.Id == id1)
.FromQuery(
fsql.Select<User1>()
.WithParameters(dbpars)
.Where(a => a.Id == id2)
)
.InnerJoin((a,b) => a.Id == b.Id)
.ToSql(); SELECT a."Id", a."GroupId", a."Username"
FROM (
SELECT a."Id", a."GroupId", a."Username"
FROM "User1" a
WHERE (a."Id" = @exp_0)
) a
INNER JOIN (
SELECT a."Id", a."GroupId", a."Username"
FROM "User1" a
WHERE (a."Id" = @exp_1) ) b ON b."Id" = a."Id" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
问题:开启参数化查询,使用Where条件+子查询有一定概率出现异常:“必须声明标量变量 "@exp_0"
开发框架:.NET 5.0
FreeSql版本:3.2.662
数据库版本:Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64) Sep 24 2019 13:48:23 Copyright (C) 2019 Microsoft Corporation Enterprise Edition (64-bit) on Windows 10 Pro 10.0 (Build 19042: )
重现步骤
1.开启参数化查询
2.同时包含Where以及子查询:
生成的SQL语句:
异常信息:
异常出现概率不定,但在有一定并发量时,或使用比较复杂语句时出现概率较高
PS:可提供重现demo
The text was updated successfully, but these errors were encountered: