Skip to content
Open
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 @@ -34,6 +34,9 @@ public static readonly MethodInfo PopulateListMethod
private static readonly bool UseOldBehavior37162 =
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue37162", out var enabled37162) && enabled37162;

private static readonly bool UseOldBehavior37304 =
AppContext.TryGetSwitch("Microsoft.EntityFrameworkCore.Issue37304", out var enabled37304) && enabled37304;

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
Expand Down Expand Up @@ -207,7 +210,12 @@ IServiceProperty serviceProperty

IComplexProperty complexProperty
=> CreateMaterializeExpression(
new StructuralTypeMaterializerSourceParameters(complexProperty.ComplexType, "complexType", complexProperty.ClrType, nullable || complexProperty.IsNullable, QueryTrackingBehavior: null),
new StructuralTypeMaterializerSourceParameters(
complexProperty.ComplexType,
"complexType",
complexProperty.ClrType,
UseOldBehavior37304 ? nullable || complexProperty.IsNullable : complexProperty.IsNullable,
QueryTrackingBehavior: null),
bindingInfo.MaterializationContextExpression),

_ => throw new UnreachableException()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,80 @@ public class ComplexTypeWithAllNulls

#endregion 37162

#region 37304

[ConditionalFact]
public virtual async Task Non_optional_complex_type_with_all_nullable_properties_via_left_join()
{
var contextFactory = await InitializeAsync<Context37304>(
seed: context =>
{
context.Add(
new Context37304.Parent
{
Id = 1,
Children =
[
new Context37304.Child
{
Id = 1,
ComplexType = new Context37304.ComplexTypeWithAllNulls()
}
]
});
return context.SaveChangesAsync();
});

await using var context = contextFactory.CreateContext();

var parent = await context.Set<Context37304.Parent>().Include(p => p.Children).SingleAsync();

var child = parent.Children.Single();
Assert.NotNull(child.ComplexType);
Assert.Null(child.ComplexType.NullableString);
Assert.Null(child.ComplexType.NullableDateTime);
}

private class Context37304(DbContextOptions options) : DbContext(options)
{
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<Parent>(b =>
{
b.Property(p => p.Id).ValueGeneratedNever();
});

modelBuilder.Entity<Child>(b =>
{
b.Property(c => c.Id).ValueGeneratedNever();
b.HasOne(c => c.Parent).WithMany(p => p.Children).HasForeignKey(c => c.ParentId);
b.ComplexProperty(c => c.ComplexType);
});
}

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

public class Child
{
public int Id { get; set; }
public int ParentId { get; set; }
public Parent Parent { get; set; } = null!;
public ComplexTypeWithAllNulls ComplexType { get; set; } = null!;
}

public class ComplexTypeWithAllNulls
{
public string? NullableString { get; set; }
public DateTime? NullableDateTime { get; set; }
}
}

#endregion 37304

#region Issue37337

[ConditionalFact]
Expand Down
Loading