Closed PawelGerr closed 2 years ago
This is a regression caused by the fix to https://github.com/dotnet/efcore/issues/27102
Unfortunately the complete fix for both issues would be too risky for a patch. You can disable the fix for #27102 by calling this on startup:
AppContext.SetSwitch("Microsoft.EntityFrameworkCore.Issue27102", true);
Hello I have the same problem,I can not disable these #27102 because I need it. Also, some other problems have been fixed in 6.0.2 and I need them too and I can not stay in version 6.0.1. Is not there a better solution until the release of version 7.0.0?
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 Contains(string)
.
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 https://github.com/npgsql/npgsql/issues/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 Contains(DbParameter)
(or rather Contains(SqlParameter)
since I was running test against SqlServer provider) and it failed to find it even though it was same parameter reference. I will try to use string version and hope for the best.
Let me know if it doesn't work somehow, I can investigate.
Similar as in https://github.com/dotnet/efcore/issues/26754 and https://github.com/dotnet/efcore/issues/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