Skip to content

Commit

Permalink
Query: Identify Contains on IReadOnlySet/IImmutableSet
Browse files Browse the repository at this point in the history
Resolves #26437
  • Loading branch information
smitpatel committed Oct 28, 2021
1 parent 90f0808 commit 7e75895
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 1 deletion.
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

0 comments on commit 7e75895

Please sign in to comment.