diff --git a/test/EFCore.Specification.Tests/Query/PrimitiveCollectionsQueryTestBase.cs b/test/EFCore.Specification.Tests/Query/PrimitiveCollectionsQueryTestBase.cs index ce390626e95..bdda2d187f6 100644 --- a/test/EFCore.Specification.Tests/Query/PrimitiveCollectionsQueryTestBase.cs +++ b/test/EFCore.Specification.Tests/Query/PrimitiveCollectionsQueryTestBase.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System.Collections.Frozen; using System.Collections.Immutable; namespace Microsoft.EntityFrameworkCore.Query; @@ -10,6 +11,8 @@ public abstract class PrimitiveCollectionsQueryTestBase(TFixture fixtu { public virtual int? NumberOfValuesForHugeParameterCollectionTests { get; } = null; + private static readonly FrozenSet StaticFrozenInts = new[] { 10, 999 }.ToFrozenSet(); + [ConditionalFact] public virtual Task Inline_collection_of_ints_Contains() => AssertQuery(ss => ss.Set().Where(c => new[] { 10, 999 }.Contains(c.Int))); @@ -267,6 +270,22 @@ public virtual async Task Parameter_collection_ImmutableArray_of_ints_Contains_i await AssertQuery(ss => ss.Set().Where(c => !ints.Contains(c.Int))); } + [ConditionalFact] + public virtual async Task Parameter_collection_FrozenSet_of_ints_Contains_int() + { + var ints = new[] { 10, 999 }.ToFrozenSet(); + + await AssertQuery(ss => ss.Set().Where(c => ints.Contains(c.Int))); + await AssertQuery(ss => ss.Set().Where(c => !ints.Contains(c.Int))); + } + + [ConditionalFact] + public virtual async Task Parameter_collection_static_readonly_FrozenSet_of_ints_Contains_int() + { + await AssertQuery(ss => ss.Set().Where(c => StaticFrozenInts.Contains(c.Int))); + await AssertQuery(ss => ss.Set().Where(c => !StaticFrozenInts.Contains(c.Int))); + } + [ConditionalFact] public virtual async Task Parameter_collection_of_ints_Contains_nullable_int() { diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs index 0583fd68035..ecbf0073610 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/PrimitiveCollectionsQuerySqlServerTest.cs @@ -567,6 +567,54 @@ WHERE [p].[Int] NOT IN (@ints1, @ints2) """); } + public override async Task Parameter_collection_FrozenSet_of_ints_Contains_int() + { + await base.Parameter_collection_FrozenSet_of_ints_Contains_int(); + + AssertSql( + """ +@ints1='10' +@ints2='999' + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[NullableWrappedId], [p].[NullableWrappedIdWithNullableComparer], [p].[String], [p].[Strings], [p].[WrappedId] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Int] IN (@ints1, @ints2) +""", + // + """ +@ints1='10' +@ints2='999' + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[NullableWrappedId], [p].[NullableWrappedIdWithNullableComparer], [p].[String], [p].[Strings], [p].[WrappedId] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Int] NOT IN (@ints1, @ints2) +"""); + } + + public override async Task Parameter_collection_static_readonly_FrozenSet_of_ints_Contains_int() + { + await base.Parameter_collection_static_readonly_FrozenSet_of_ints_Contains_int(); + + AssertSql( + """ +@StaticFrozenInts1='10' +@StaticFrozenInts2='999' + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[NullableWrappedId], [p].[NullableWrappedIdWithNullableComparer], [p].[String], [p].[Strings], [p].[WrappedId] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Int] IN (@StaticFrozenInts1, @StaticFrozenInts2) +""", + // + """ +@StaticFrozenInts1='10' +@StaticFrozenInts2='999' + +SELECT [p].[Id], [p].[Bool], [p].[Bools], [p].[DateTime], [p].[DateTimes], [p].[Enum], [p].[Enums], [p].[Int], [p].[Ints], [p].[NullableInt], [p].[NullableInts], [p].[NullableString], [p].[NullableStrings], [p].[NullableWrappedId], [p].[NullableWrappedIdWithNullableComparer], [p].[String], [p].[Strings], [p].[WrappedId] +FROM [PrimitiveCollectionsEntity] AS [p] +WHERE [p].[Int] NOT IN (@StaticFrozenInts1, @StaticFrozenInts2) +"""); + } + public override async Task Parameter_collection_of_ints_Contains_nullable_int() { await base.Parameter_collection_of_ints_Contains_nullable_int();