Skip to content
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
12 changes: 8 additions & 4 deletions src/EFCore.Relational/Query/SqlNullabilityProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,8 @@ ParameterizedCollectionMode is ParameterizedCollectionMode.Constants
||
(ParameterizedCollectionMode is ParameterizedCollectionMode.MultipleParameters
&& valuesParameter.ShouldBeConstantized);
var useParameter = ParameterizedCollectionMode is ParameterizedCollectionMode.Parameter
&& !valuesParameter.ShouldBeConstantized;
var expandedParameters = _collectionParameterExpansionMap.GetOrAddNew(valuesParameter);
var expandedParametersCounter = 0;
for (var i = 0; i < values.Count; i++)
Expand All @@ -840,9 +842,11 @@ ParameterizedCollectionMode is ParameterizedCollectionMode.Constants
continue;
}

switch (useParameters, useConstants)
switch (useParameters, useConstants, useParameter)
{
case (true, false):
case (true, false, false):
// see #36311 for more info
case (false, false, true):
{
// Create parameter for value if we didn't create it yet,
// otherwise reuse it.
Expand All @@ -860,7 +864,7 @@ ParameterizedCollectionMode is ParameterizedCollectionMode.Constants
break;
}

case (false, true):
case (false, true, false):
{
processedValues.Add(_sqlExpressionFactory.Constant(values[i], values[i]?.GetType() ?? typeof(object), sensitive: true, elementTypeMapping));

Expand All @@ -869,7 +873,7 @@ ParameterizedCollectionMode is ParameterizedCollectionMode.Constants

default:
throw new UnreachableException();
};
}
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,45 @@ public class TestEntity
public static readonly IEnumerable<object[]> InlinedRedactingData = [[true, true], [true, false], [false, true], [false, false]];

#endregion

#region 36311

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public async Task Entity_equality_with_Contains_and_Parameter(bool async)
{
var contextFactory = await InitializeAsync<Context36311>(
onConfiguring: o => SetParameterizedCollectionMode(o, ParameterizedCollectionMode.Parameter));
using var context = contextFactory.CreateContext();

List<Context36311.BlogDetails> details = [new Context36311.BlogDetails { Id = 1 }, new Context36311.BlogDetails { Id = 2 }];
var query = context.Blogs.Where(b => details.Contains(b.Details));

var result = async
? await query.ToListAsync()
: query.ToList();
}

protected class Context36311(DbContextOptions options) : DbContext(options)
{
public DbSet<Blog> Blogs { get; set; }

public class Blog
{
public int Id { get; set; }
public string Name { get; set; }

public BlogDetails Details { get; set; }
}

public class BlogDetails
{
public int Id { get; set; }
public string Name { get; set; }
}
}

#endregion
}
}

Expand Down