小编Wil*_*een的帖子

一对一关系,一侧没有引用属性

我有以下构造;具有地址(ownsone、子实体)和国家/地区地址(hasone、一对一)的人

public class Person
{
     public Guid Id {get; set;}
     public string Name {get; set;}
     public Address Address {get; set;}
}

public class Address 
{
     public Guid Id {get; set;}
     public Guid CountryId {get; set;}
     public Country Country {get; set;}
}

public class Country
{
     public Guid Id {get; set;}
     public string CountryCode {get; set;}
}

public class EntityConfiguration<Person> where Person : class
{
     public void Configure(EntityBuilder<Person> builder)
     {
         builder.OwnsOne(p => p.Address, addressBuilder => 
         addressBuilder.HasOne(address => address.Country).WithOne();
     }
}
Run Code Online (Sandbox Code Playgroud)

当我运行 …

c# entity-framework-core

3
推荐指数
1
解决办法
3550
查看次数

标签 统计

c# ×1

entity-framework-core ×1