0

私はモデルを持っています

ハブ - < セクション

セクションはツリー階層ですが、それらはすべてハブに属します (1 つのセクションがツリーに 2 回出現する可能性があるため、階層を管理する別のテーブルがあります)。

ハブにはルート セクションも必要なので、私のハブ エンティティには次のものがあります。

public partial class Hub
{
    public Hub()
    {
        this.Sections = new List<Section>();
    }

    public int HubId { get; set; }
    public string Name { get; set; }
    public virtual ICollection<Section> Sections { get; set; }

    public int RootSectionId { get; set; }
    public virtual Section RootSection { get; set; }
}

次のようにマッピングを設定しない場合:

public class HubMap : EntityTypeConfiguration<Hub>
{
    public HubMap()
    {
        // Primary Key
        this.HasKey(t => t.HubId);


        // Table & Column Mappings
        this.ToTable("Hubs");
        this.Property(t => t.HubId).HasColumnName("HubId");
        this.Property(t => t.Name).HasColumnName("Name");

        // Relationships
        this.HasRequired(t => t.Site)
            .WithMany(t => t.Hubs)
            .HasForeignKey(d => d.SiteId);

     }
}

RootSection_SectionId 列が見つからないというエラーが表示されます。これで、一致するように列の名前を変更できますが、EF マッピングを理解するために、「RootSectionId」である列を指定できるようにしたいと考えています。

このフィールドをマッピングするには、マッピング ファイルに何を含める必要がありますか?

4

1 に答える 1

1

何かのようなもの :

this.HasRequired(t => t.RootSection)
    .WithMany()
    .HasForeignKey(d => d.RootSectionId);
于 2013-10-05T20:00:14.807 に答える