EF Core 3.1 OwnsOne Required Properties Are Null

Viewed 1053

When I use the following code in my EF Core 3.1.2 Entity Configuration, EF Migrations generates EarliestTime and LatestTime Properties (both are DateTimeOffset types) of the DestScheduleWindow owned entity to Nullable:True. I would expect these to be Nullable:False because both properties are marked as Required and I'm using Non Nullable ref types (tried both ways just in case). Is it possible to have the properties on an Owned Type properties to be Non Nullable as generated by EF Migrations? When I search, it seems like everyone is looking for nullable owned types rather than non nullable owned types.

Nullable Owned types in EF Core

builder.OwnsOne(p => p.DestScheduledWindow, lt =>
                {
                    lt.Property(x => x.EarliestTime).IsRequired(true);
                    lt.Property(x => x.LatestTime).IsRequired(true);
                    lt.OwnsOne(p => p.LocationTimeZone,
                        pc => { pc.Property(p => p.TimeZoneCode).HasMaxLength(10).IsUnicode(false); });
                    lt.WithOwner();
                }
            );
0 Answers
Related