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



我试图定义更接近域模型的数据模型,但我认为Ef不支持这种简单的需求。我曾与ownsMany、ownsOne、hasMany、hasOne、with Owner、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核心添加迁移称:

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'.

我试图找到最好的答案,所以在实体框架核心的官方GitHub存储库上提出了一个问题:https://github.com/dotnet/efcore并发现错误消息不合适,开发团队将此功能添加到下一个sprints积压工作中。

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

最新更新