如何使用Entity Framework Core 3.0创建必需的拥有的类型 [英] How can I create a Required Owned Type with Entity Framework Core 3.0
本文介绍了如何使用Entity Framework Core 3.0创建必需的拥有的类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在努力使用Entity Framework Core创建不可为空/必需的拥有类型。
我对PostgreSQL数据库使用EF Core 3.0。
I'm struggling creating a non-nullable/required Owned Type with Entity Framework Core. I'm using EF Core 3.0 against PostgreSQL database.
我的值对象:
public class PersonName
{
public PersonName(string name)
{
this.Name = name;
}
public string Name { get; set; }
}
我的实体:
public class Person
{
public int Id { get; set; }
public virtual PersonName FullName { get; set; }
}
我的实体配置:
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");
});
}
值类型属性已成功保留在数据库的人表中但是,尽管我使用的是'IsRequired()'方法,但列仍为空。
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.
非常感谢!
推荐答案
原来是个问题。
[必需] / IsRequired()对拥有实体的属性的忽略
在此处解决,所以请竖起大拇指。 (:
It will be tackled here so please thumb-up. (:
这篇关于如何使用Entity Framework Core 3.0创建必需的拥有的类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文