-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Regression in 6.0.2: The variable name '@p0' has already been declared. #27427
Comments
Hello |
…diately instead of deferred This should be the expected behavior, because I can't image why I would create a parameter, then modify the underlying (in-memory-)collection and in the end execute the query expecting it has the last modifications. And there is a regression in 6.0.2 (dotnet/efcore#27427)
We are going to investigate whether there is a less risky way to fix this, but it will take us some time and might not make it to 6.0.4 |
@roji to do some research. |
@smitpatel if I understood correctly, you needed a way to find out if a parameter is already present in a DbParameterCollection - there's Note Dapper doing what may be a similar thing here: first check if a parameter with a given name is in the collection, and add if not. If it's good enough for them it's probably good enough for us. For reference, some providers have perf issues with this pattern (in Npgsql 6 we optimized this in npgsql/npgsql#3978). But this only shows up with a lot of parameters, and it's the ADO.NET provider's problem, not EF's. Note that at some point we probably want to support unnamed/positional parameters (#27377), at which point we'll have to reexamine this (but other parts already don't support unnamed, so we can forget about that for now...). Let me know if you need something else! |
I tried using |
Let me know if it doesn't work somehow, I can investigate. |
Resolves #27427 If a FromSql with DbParameter is reused in multiple parts of query then we need to add the DbParameter only once
Resolves #27427 If a FromSql with DbParameter is reused in multiple parts of query then we need to add the DbParameter only once
Resolves #27427 If a FromSql with DbParameter is reused in multiple parts of query then we need to add the DbParameter only once
Similar as in #26754 and #26632 but during reading data.
The issue seem to affect
Microsoft.EntityFrameworkCore.SqlServer v6.0.2
only. No issues withMicrosoft.EntityFrameworkCore.SqlServer v6.0.1
andMicrosoft.EntityFrameworkCore.Sqlite v6.0.2
.Repro
csproj file
DbContext and Entity
Program.cs
The issue comes only when using
FromSqlRaw
+SqlParameter
+GroupBy
+Select
, which has an aggregate likeg.Count()
.No issues when using
.FromSqlInterpolated($"SELECT * FROM DemoEntities WHERE Id = {Guid.Empty}")
or.FromSqlRaw("SELECT * FROM DemoEntities WHERE Id = {0}", Guid.Empty)
Logs
provider and version information
EF Core version: 6.0.2
Database provider: Microsoft.EntityFrameworkCore.SqlServer
Target framework: .NET 6.0
Operating system: win10 x64
IDE: JetBrains Rider 2021.3.3
The text was updated successfully, but these errors were encountered: