I'm struggling creating a non-nullable/required Owned Type with Entity Framework Core. I'm using EF Core 3.0 against PostgreSQL database.
My value object:
public class PersonName
{
public PersonName(string name)
{
this.Name = name;
}
public string Name { get; set; }
}
My entity:
public class Person
{
public int Id { get; set; }
public virtual PersonName FullName { get; set; }
}
My entity configuration:
public void Configure(EntityTypeBuilder<Person> builder)
{
builder.ToTable(nameof(Person));
builder.HasKey(person => person.Id);
builder.OwnsOne(person => person.FullName, personName =>
{
personName.Property(pn => pn.Name).IsRequired().HasColumnName("FullName");
});
}
The value type property is successfully persisted into the 'Person' table in the database but the column apears to be nullable despite that I'm using 'IsRequired()' method.
Thanks a lot!