Skip to content
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

Query: Identify Contains on IReadOnlySet/IImmutableSet #26487

Merged
1 commit merged into from
Nov 1, 2021
Merged
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
7 changes: 6 additions & 1 deletion src/Shared/MethodInfoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;

#nullable enable
Expand All @@ -16,6 +17,10 @@ public static bool IsContainsMethod(this MethodInfo method)
&& method.DeclaringType != null
&& method.DeclaringType.GetInterfaces().Append(method.DeclaringType).Any(
t => t == typeof(IList)
|| (t.IsGenericType && t.GetGenericTypeDefinition() == typeof(ICollection<>)));
|| (t.IsGenericType
&& t.GetGenericTypeDefinition() is Type genericType
&& (genericType == typeof(ICollection<>)
|| genericType == typeof(IReadOnlySet<>)
|| genericType == typeof(IImmutableSet<>))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1452,6 +1452,26 @@ FROM root c
WHERE ((c[""Discriminator""] = ""Order"") AND c[""OrderID""] IN (10248, 10249))");
}

public override async Task IImmutableSet_Contains_with_parameter(bool async)
{
await base.IImmutableSet_Contains_with_parameter(async);

AssertSql(
@"SELECT c
FROM root c
WHERE ((c[""Discriminator""] = ""Customer"") AND c[""CustomerID""] IN (""ALFKI""))");
}

public override async Task IReadOnlySet_Contains_with_parameter(bool async)
{
await base.IReadOnlySet_Contains_with_parameter(async);

AssertSql(
@"SELECT c
FROM root c
WHERE ((c[""Discriminator""] = ""Customer"") AND c[""CustomerID""] IN (""ALFKI""))");
}

public override async Task HashSet_Contains_with_parameter(bool async)
{
await base.HashSet_Contains_with_parameter(async);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1537,6 +1537,30 @@ public virtual Task Contains_with_constant_list_value_type_id(bool async)
entryCount: 2);
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task IImmutableSet_Contains_with_parameter(bool async)
{
IImmutableSet<string> ids = ImmutableHashSet<string>.Empty.Add("ALFKI");

return AssertQuery(
async,
ss => ss.Set<Customer>().Where(c => ids.Contains(c.CustomerID)),
entryCount: 1);
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task IReadOnlySet_Contains_with_parameter(bool async)
{
IReadOnlySet<string> ids = new HashSet<string> { "ALFKI" };

return AssertQuery(
async,
ss => ss.Set<Customer>().Where(c => ids.Contains(c.CustomerID)),
entryCount: 1);
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task HashSet_Contains_with_parameter(bool async)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1758,6 +1758,26 @@ FROM [Orders] AS [o]
WHERE [o].[OrderID] IN (10248, 10249)");
}

public override async Task IImmutableSet_Contains_with_parameter(bool async)
{
await base.IImmutableSet_Contains_with_parameter(async);

AssertSql(
@"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region]
FROM [Customers] AS [c]
WHERE [c].[CustomerID] = N'ALFKI'");
}

public override async Task IReadOnlySet_Contains_with_parameter(bool async)
{
await base.IReadOnlySet_Contains_with_parameter(async);

AssertSql(
@"SELECT [c].[CustomerID], [c].[Address], [c].[City], [c].[CompanyName], [c].[ContactName], [c].[ContactTitle], [c].[Country], [c].[Fax], [c].[Phone], [c].[PostalCode], [c].[Region]
FROM [Customers] AS [c]
WHERE [c].[CustomerID] = N'ALFKI'");
}

public override async Task HashSet_Contains_with_parameter(bool async)
{
await base.HashSet_Contains_with_parameter(async);
Expand Down