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

Code before:
                        new PrincipalDerived<DependentBase<byte?>>
                        {
                            Id = 2,
                            AlternateId = new Guid(),
                            Dependent = new DependentBase<byte?>(1),
                            Owned = new OwnedType(c)
                        });
                }

                await c.SaveChangesAsync();
            },
            options: new CompiledModelCodeGenerationOptions { UseNullableReferenceTypes = true, ForNativeAot = true });

    [ConditionalFact]
    public virtual Task CompiledModelBackingFieldNotFound()
        => Test(
            modelBuilder =>
            {
                modelBuilder.Entity<EntityWithNoBackingFieldCollection>(eb =>
                {
                    eb.Property(e => e.Collection)
                        .UsePropertyAccessMode(PropertyAccessMode.FieldDuringConstruction);
                });
            },
            options: new CompiledModelCodeGenerationOptions { ForNativeAot = true },
            expectedExceptionMessage: DesignStrings.CompiledModelBackingFieldNotFound("EntityWithNoBackingFieldCollection", "Collection"));

    protected virtual void BuildComplexTypesModel(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<PrincipalBase>(eb =>
        {
            eb.Ignore(e => e.Owned);

            eb.Property("FlagsEnum2");

            eb.ComplexProperty(
                e => e.Owned, eb =>
                {
                    eb.HasField("_ownedField")
                        .UsePropertyAccessMode(PropertyAccessMode.Field)
                        .HasChangeTrackingStrategy(ChangeTrackingStrategy.ChangingAndChangedNotificationsWithOriginalValues)
                        .HasPropertyAnnotation("goo", "ber")
                        .HasTypeAnnotation("go", "brr");
                    eb.Property(c => c.Details)
                        .IsUnicode(false)
                        .IsRequired(false)
                        .HasField("_details")
                        .HasSentinel("")
                        .UsePropertyAccessMode(PropertyAccessMode.FieldDuringConstruction)
                        .HasMaxLength(64)
                        .HasPrecision(3, 2)

Review comment (bug):
This test configures `PropertyAccessMode.FieldDuringConstruction` on an `IList<int>` property. Depending on provider conventions, `IList<T>` may be treated as a primitive collection (`IPropertyBase.IsCollection == true`), in which case `TryGetMemberInfo(..., forSet: true, ...)` can succeed with `memberInfo == null` and the code generator won’t throw—making the test brittle across providers. Consider using a non-collection scalar property (e.g. a computed `int` property without a backing field) to deterministically exercise the “no backing field / no setter” failure path.
```suggestion
    protected class EntityWithNoBackingFieldScalar
    {
        public int Computed => 42;
    }

    [ConditionalFact]
    public virtual Task CompiledModelBackingFieldNotFound()
        => Test(
            modelBuilder =>
            {
                modelBuilder.Entity<EntityWithNoBackingFieldScalar>(eb =>
                {
                    eb.Property(e => e.Computed)
                        .UsePropertyAccessMode(PropertyAccessMode.FieldDuringConstruction);
                });
            },
            options: new CompiledModelCodeGenerationOptions { ForNativeAot = true },
            expectedExceptionMessage: DesignStrings.CompiledModelBackingFieldNotFound("EntityWithNoBackingFieldScalar", "Computed"));
```

Code after:
                        {
                            Id = 2,
                            AlternateId = new Guid(),
                            Dependent = new DependentBase<byte?>(1),
                            Owned = new OwnedType(c)
                        });
                }

                await c.SaveChangesAsync();
            },
            options: new CompiledModelCodeGenerationOptions { UseNullableReferenceTypes = true, ForNativeAot = true });

    [ConditionalFact]
    public virtual Task Throws_for_Backing_Field_Not_Found()
        => Test(
            modelBuilder =>
            {
                modelBuilder.Entity<EntityWithNoBackingFieldScalar>(eb =>
                {
                    eb.Property(e => e.Computed)
                        .UsePropertyAccessMode(PropertyAccessMode.FieldDuringConstruction);
                });
            },
            options: new CompiledModelCodeGenerationOptions { ForNativeAot = true },
            expectedExceptionMessage: CoreStrings.NoFieldOrSetter("Computed", "EntityWithNoBackingFieldScalar"),
            skipValidation: true);

    protected virtual void BuildComplexTypesModel(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<PrincipalBase>(eb =>
        {
            eb.Ignore(e => e.Owned);

            eb.Property("FlagsEnum2");

            eb.ComplexProperty(
                e => e.Owned, eb =>
                {
                    eb.HasField("_ownedField")
                        .UsePropertyAccessMode(PropertyAccessMode.Field)
                        .HasChangeTrackingStrategy(ChangeTrackingStrategy.ChangingAndChangedNotificationsWithOriginalValues)
                        .HasPropertyAnnotation("goo", "ber")
                        .HasTypeAnnotation("go", "brr");
                    eb.Property(c => c.Details)
                        .IsUnicode(false)
                        .IsRequired(false)
                        .HasField("_details")
                        .HasSentinel("")
                        .UsePropertyAccessMode(PropertyAccessMode.FieldDuringConstruction)
                        .HasMaxLength(64)
                        .HasPrecision(3, 2)