Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,6 +11,8 @@ public abstract class PrimitiveCollectionsQueryTestBase<TFixture>(TFixture fixtu
{
public virtual int? NumberOfValuesForHugeParameterCollectionTests { get; } = null;

private static readonly FrozenSet<int> StaticFrozenInts = new[] { 10, 999 }.ToFrozenSet();

[ConditionalFact]
public virtual Task Inline_collection_of_ints_Contains()
=> AssertQuery(ss => ss.Set<PrimitiveCollectionsEntity>().Where(c => new[] { 10, 999 }.Contains(c.Int)));
Expand Down Expand Up @@ -267,6 +270,22 @@ public virtual async Task Parameter_collection_ImmutableArray_of_ints_Contains_i
await AssertQuery(ss => ss.Set<PrimitiveCollectionsEntity>().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<PrimitiveCollectionsEntity>().Where(c => ints.Contains(c.Int)));
await AssertQuery(ss => ss.Set<PrimitiveCollectionsEntity>().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<PrimitiveCollectionsEntity>().Where(c => StaticFrozenInts.Contains(c.Int)));
await AssertQuery(ss => ss.Set<PrimitiveCollectionsEntity>().Where(c => !StaticFrozenInts.Contains(c.Int)));
}

[ConditionalFact]
public virtual async Task Parameter_collection_of_ints_Contains_nullable_int()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading