Repository: dotnet/efcore
File: test/EFCore.Specification.Tests/Query/AdHocComplexTypeQueryTestBase.cs (C#)

Code before:

        public class EntityType
        {
            public int Id { get; set; }
            public ComplexTypeWithAllNulls NonOptionalComplexType { get; set; } = null!;
        }

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

    #endregion 37162

    #region Issue37634

    [ConditionalFact]
    public virtual async Task Nullable_complex_type_with_discriminator_and_shadow_property()
    {
        var contextFactory = await InitializeAsync<Context37634>(
            seed: context =>
            {
                context.Add(
                    new Context37634.EntityType
                    {
                        Prop = new Context37634.OptionalComplexProperty
                        {
                            OptionalValue = true
                        }
                    });
                return context.SaveChangesAsync();
            });

        await using var context = contextFactory.CreateContext();

        var entities = await context.Set<Context37634.EntityType>().ToArrayAsync();

        Assert.Single(entities);
        var entity = entities[0];
        Assert.NotNull(entity.Prop);
        Assert.True(entity.Prop.OptionalValue);
    }

    private class Context37634(DbContextOptions options) : DbContext(options)
    {
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            var entity = modelBuilder.Entity<EntityType>();
            entity.Property(p => p.Id);

Review comment (suggestion):
The entity instantiation references "Context37634.EntityType", but this should be "Context37337.EntityType" to match the issue number being fixed.

Code after:

        public class EntityType
        {
            public int Id { get; set; }
            public ComplexTypeWithAllNulls NonOptionalComplexType { get; set; } = null!;
        }

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

    #endregion 37162

    #region Issue37337

    [ConditionalFact]
    public virtual async Task Nullable_complex_type_with_discriminator_and_shadow_property()
    {
        var contextFactory = await InitializeAsync<Context37337>(
            seed: context =>
            {
                context.Add(
                    new Context37337.EntityType
                    {
                        Prop = new Context37337.OptionalComplexProperty
                        {
                            OptionalValue = true
                        }
                    });
                return context.SaveChangesAsync();
            });

        await using var context = contextFactory.CreateContext();

        var entities = await context.Set<Context37337.EntityType>().ToArrayAsync();

        Assert.Single(entities);
        var entity = entities[0];
        Assert.NotNull(entity.Prop);
        Assert.True(entity.Prop.OptionalValue);
    }

    private class Context37337(DbContextOptions options) : DbContext(options)
    {
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            var entity = modelBuilder.Entity<EntityType>();
            entity.Property(p => p.Id);