如何使用此架构进行配置?
CREATE TABLE Entity
(
Id int identity primary key,
Name nvarchar(30)
)
CREATE TABLE Member
(
ParentEntityId references Entity(Id),
ChildEntityId references Entity(Id)
)
答案 0 :(得分:2)
像这样:
模特课:
public class Entity
{
public int Id { get; set; }
public string Name { get; set; }
public ICollection<Entity> Parents { get; set; }
public ICollection<Entity> Children { get; set; }
}
映射:
modelBuilder.Entity<Entity>()
.HasMany(e => e.Parents)
.WithMany(e => e.Children)
.Map(m =>
{
m.ToTable("Member");
m.MapLeftKey("ParentEntityId");
m.MapRightKey("ChildEntityId");
});