'EF Core 3.1 value object is nullable after add migration, while in Fluent API it's mandatory

I have created a ValueObject called Discount as below:

public class Discount:ValueObject
{
    public int          Value { get; }
    public DiscountUnit Unit  { get; }
    // Code removed for brevity
}

In FluentApi configuration I use the OwnsOne method like this:

builder.OwnsOne(x => x.Discount, b => {
                                          b.Property(x => x.Value)
                                              .IsRequired(true);
                                          b.Property(x => x.Unit)
                                              .HasConversion(s => s.ToString(),
                                                             x => (DiscountUnit) Enum.Parse( typeof(DiscountUnit), x))
                                              .IsRequired(true);
                                        } );

When I update the database, Value and Unit are nullable while they are required.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source