【发布时间】:2013-11-24 23:17:15
【问题描述】:
问题:我能够保存到自引用集合,但实体框架在保存到数据库后不会在集合中显示它们。
期望:通过{entity}.{collection}.{query()};访问集合中的实体
实体:
class Feat
{
public Feat()
{
PrerequisiteFeats = new HashSet<Feat>();
}
public int Id { get; set; }
// Other properties here
public virtual ICollection<Feat> PrerequisiteFeats { get; set; }
}
上下文:
class PathfinderContext : DbContext
{
public DbSet<Feat> Feats { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<Feat>()
.HasMany(feat => feat.PrerequisiteFeats)
.WithMany()
.Map(m =>
{
m.MapLeftKey("FeatId");
m.MapRightKey("PrerequisiteFeatId");
m.ToTable("PrerequisiteFeats");
});
}
}
【问题讨论】:
标签: c# .net database entity-framework