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
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,13 @@ Expression CompensateForCollectionMaterialization(ParameterExpression parameter,
{
if (_containsCollectionMaterialization)
{
_valuesArrayInitializers!.Add(parameter);
var expressionToAdd = (Expression)parameter;
if (expressionToAdd.Type.IsValueType)
{
expressionToAdd = Convert(expressionToAdd, typeof(object));
}

_valuesArrayInitializers!.Add(expressionToAdd);
return Convert(
ArrayIndex(
_valuesArrayExpression!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ FROM root c
}


// Cosmos doesn't support entity collection navigations across documents
public override Task Project_struct_complex_type_with_entity_collection_navigation()
=> Task.CompletedTask;

[ConditionalFact]
public virtual void Check_all_tests_overridden()
=> TestHelpers.AssertAllMethodsOverridden(GetType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,70 @@ namespace Microsoft.EntityFrameworkCore.Query.Associations.ComplexProperties;

public abstract class ComplexPropertiesCollectionTestBase<TFixture>(TFixture fixture)
: AssociationsCollectionTestBase<TFixture>(fixture)
where TFixture : ComplexPropertiesFixtureBase, new();
where TFixture : ComplexPropertiesFixtureBase, new()
{
#region 37926

[ConditionalFact]
public virtual async Task Project_struct_complex_type_with_entity_collection_navigation()
{
var contextFactory = await InitializeNonSharedTest<Context37926>(
seed: async context =>
{
context.Add(new Context37926.Parent
{
Id = 1,
Coords = new Context37926.Coords { X = 1, Y = 2 },
Children = [new() { Id = 1, Name = "Child1" }]
});
await context.SaveChangesAsync();
});

await using var context = contextFactory.CreateDbContext();

var result = await context.Set<Context37926.Parent>()
.OrderBy(p => p.Id)
.Select(p => new { p.Coords, p.Children })
.FirstAsync();

Assert.Equal(1, result.Coords.X);
Assert.Single(result.Children);
}

protected class Context37926(DbContextOptions options) : DbContext(options)
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Parent>(b =>
{
b.Property(e => e.Id).ValueGeneratedNever();
b.ComplexProperty(e => e.Coords);
b.HasMany(e => e.Children).WithOne().HasForeignKey(c => c.ParentId);
});

modelBuilder.Entity<Child>().Property(e => e.Id).ValueGeneratedNever();
}

public class Parent
{
public int Id { get; set; }
public Coords Coords { get; set; }
public List<Child> Children { get; set; } = [];
}

public struct Coords
{
public int X { get; set; }
public int Y { get; set; }
}

public class Child
{
public int Id { get; set; }
public required string Name { get; set; }
public int ParentId { get; set; }
}
}

#endregion 37926
}
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,23 @@ FROM [RootEntity] AS [r]
}
}

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

AssertSql(
"""
SELECT [p0].[Coords_X], [p0].[Coords_Y], [p0].[Id], [c].[Id], [c].[Name], [c].[ParentId]
FROM (
SELECT TOP(1) [p].[Coords_X], [p].[Coords_Y], [p].[Id]
FROM [Parent] AS [p]
ORDER BY [p].[Id]
) AS [p0]
LEFT JOIN [Child] AS [c] ON [p0].[Id] = [c].[ParentId]
ORDER BY [p0].[Id]
""");
}

[ConditionalFact]
public virtual void Check_all_tests_overridden()
=> TestHelpers.AssertAllMethodsOverridden(GetType());
Expand Down
Loading