我是EF的新手.我遇到了创建多对多自引用关系的问题.我尝试使用以下解决方案: 实体框架核心:与同一实体的多对多关系
我的实体:
public class WordEntity
{
public long Id { get; set; }
public string Name { get; set; }
public string Json { get; set; }
public virtual List<WordSinonymEntity> Sinonyms { get; set; }
}
public class WordSinonymEntity
{
public long WordId { get; set; }
public virtual WordEntity Word { get; set; }
public long SinonymId { get; set; }
public virtual WordEntity Sinonym { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
和下一个配置:
modelBuilder.Entity<WordSinonymEntity>()
.HasOne(pt => pt.Sinonym)
.WithMany(p => p.Sinonyms) …Run Code Online (Sandbox Code Playgroud)