Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Expand Up @@ -151,10 +151,23 @@ protected virtual ValuesExpression ApplyTypeMappingsOnValuesExpression(ValuesExp
{
var value = rowValue.Values[j];

if (value.TypeMapping is null
&& inferredTypeMappings[j] is { } inferredTypeMapping)
if (value.TypeMapping is null)
{
value = _sqlExpressionFactory.ApplyTypeMapping(value, inferredTypeMapping);
if (inferredTypeMappings[j] is { } inferredTypeMapping)
{
value = _sqlExpressionFactory.ApplyTypeMapping(value, inferredTypeMapping);
}
else
{
// No type mapping was inferred from usage context (e.g. SelectMany where the value column isn't
// referenced). Fall back to the default type mapping for the CLR type.
var defaultTypeMapping = RelationalDependencies.TypeMappingSource.FindMapping(
value.Type, QueryCompilationContext.Model);
if (defaultTypeMapping is not null)
{
value = _sqlExpressionFactory.ApplyTypeMapping(value, defaultTypeMapping);
}
}
}

// We currently add explicit conversions on the first row (but not to the _ord column), to ensure that the inferred
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,11 @@ public virtual async Task Inline_collection_in_query_filter()
Assert.Equal(2, result.Id);
}

[ConditionalFact] // #38285
public virtual Task Inline_collection_SelectMany_with_unreferenced_collection_value()
Comment thread
roji marked this conversation as resolved.
=> AssertQuery(
ss => ss.Set<PrimitiveCollectionsEntity>().SelectMany(e => new[] { "a", "b" }.Select(k => e)));

[ConditionalFact]
public virtual Task Parameter_collection_Count()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,18 @@ SELECT COUNT(*)
""");
}

public override async Task Inline_collection_SelectMany_with_unreferenced_collection_value()
{
await base.Inline_collection_SelectMany_with_unreferenced_collection_value();

AssertSql(
"""
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]
CROSS APPLY (VALUES (CAST(N'a' AS nvarchar(max))), (N'b')) AS [v]([Value])
""");
}

public override async Task Parameter_collection_Count()
{
await base.Parameter_collection_Count();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2053,6 +2053,12 @@ public override async Task Column_collection_SelectMany()
SqliteStrings.ApplyNotSupported,
(await Assert.ThrowsAsync<InvalidOperationException>(() => base.Column_collection_SelectMany())).Message);

public override async Task Inline_collection_SelectMany_with_unreferenced_collection_value()
=> Assert.Equal(
SqliteStrings.ApplyNotSupported,
(await Assert.ThrowsAsync<InvalidOperationException>(
() => base.Inline_collection_SelectMany_with_unreferenced_collection_value())).Message);

public override async Task Column_collection_SelectMany_with_filter()
=> Assert.Equal(
SqliteStrings.ApplyNotSupported,
Expand Down
Loading