diff --git a/src/EFCore.SqlServer/Query/Internal/SqlServerSqlNullabilityProcessor.cs b/src/EFCore.SqlServer/Query/Internal/SqlServerSqlNullabilityProcessor.cs index 57ec6e8d1a7..38a3dde0611 100644 --- a/src/EFCore.SqlServer/Query/Internal/SqlServerSqlNullabilityProcessor.cs +++ b/src/EFCore.SqlServer/Query/Internal/SqlServerSqlNullabilityProcessor.cs @@ -18,6 +18,9 @@ public class SqlServerSqlNullabilityProcessor : SqlNullabilityProcessor { private const int MaxParameterCount = 2100; + private static readonly bool UseOldBehavior37151 = + AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue37151", out var enabled) && enabled; + /// /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in @@ -291,7 +294,8 @@ protected override int CalculateParameterBucketSize(int count, RelationalTypeMap <= 750 => 50, <= 2000 => 100, <= 2070 => 10, // try not to over-pad as we approach that limit - <= MaxParameterCount => 0, // just don't pad between 2070 and 2100, to minimize the crazy + <= MaxParameterCount when UseOldBehavior37151 => 0, + <= MaxParameterCount => 1, // just don't pad between 2070 and 2100, to minimize the crazy _ => 200, }; diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs index e212a8fe336..7d68c865f60 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs @@ -2264,6 +2264,16 @@ SELECT COUNT(*) """); } + [ConditionalFact] + public virtual async Task Parameter_collection_of_ints_Contains_int_2071_values() + { + var ints = Enumerable.Repeat(10, 2071).ToArray(); + await AssertQuery(ss => ss.Set().Where(c => ints.Contains(c.Int))); + + // check that 2071 parameter is the last one (and no error happened) + Assert.Contains("@ints2071)", Fixture.TestSqlLoggerFactory.SqlStatements[0], StringComparison.Ordinal); + } + [ConditionalFact] public virtual void Check_all_tests_overridden() => TestHelpers.AssertAllMethodsOverridden(GetType());