嵌套的自有类型包含导航 属性 - 无效

Nested Owned Type Contains Navigation Property - Not Work

我尝试将我的数据模型定义得更接近领域模型,但我认为 Ef 不支持这种简单的需求。我以不同的方式使用 ownsMany、ownsOne、hasMany、hasOne、withOwner、Navigation builder、IEntityTypeConfiguration 和...。

public class Custom
{
    [Required]
    public int id { get; set; }
    public string name { get; set; }

    public Demo demo{ get; set; }
}

[Owned()]
public class Demo  
{
    public virtual ICollection<PDemo> pDemoes{ get; set; }
}

public class PDemo
{
    [Required]
    public int id { get; set; }
    public string name { get; set; }

    [ForeignKey("Custom")]
    public int CustomId{ get; set; }
    public virtual Custom Custom{ get; set; }
}

public class RepositoryContext : DbContext
    {
        public RepositoryContext(DbContextOptions<RepositoryContext> options) : base(options)
        {

        }

        public DbSet<Custom> custom { get; set; }
        public DbSet<PDemo> pDemoes{ get; set; }
        
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
        }
}

EF Core 添加迁移说:

Unable to determine the relationship represented by navigation 'Demo.pDemoes' of type 'ICollection<PDemo>'.
Either manually configure the relationship, or ignore this property using the '[NotMapped]' attribute or 
by using 'EntityTypeBuilder.Ignore' in 'OnModelCreating'.

我试图找到最佳答案,因此请在 Entity framework Core 的官方 GitHub 存储库中提出问题: https://github.com/dotnet/efcore 并发现错误信息不合适,开发团队在下一个sprints backlog中添加了这个特性。

问题link: https://github.com/dotnet/efcore/issues/27175