0

Visual Studio 2010 .Net4 を使用しています。

EF を使用してマッパーをデータベースに構成しようとして問題が発生しています。

マップしようとしているクラスは次のとおりです。リスト内の Question オブジェクトの ParentID プロパティに基づいて、include ステートメントを使用して Children のリストを作成できるように、マップしようとしています。

public class Question
{
    public int QuestionId { get; set; }
    public int ParentId { get; set; }
    public string QuestionText { get; set; }
    public string Answer { get; set; }

    //recursive list of Questions
    public virtual List<Question> Children {get; set;}
}

そして、これがマッパーを構成する私の試みです

class QuestionConfiguration : EntityTypeConfiguration<Question>
{
    public QuestionConfiguration()
        : base()
    {
        this.HasKey(x => x.QuestionId);

        this.Property(p => p.ParentId)
            .HasColumnName("ParentId");

        this.Property(p => p.QuestionText)
            .HasColumnName("QuestionText");

        this.Property(p => p.Answer)
            .HasColumnName("Answer");

        this.HasMany(w => w.Children)
            .HasForeignKey(w => w.ParentId);

        ToTable("tbl_Questions");
    }
}

私はまだEFとc#にかなり慣れていないので、ここから始める方法がよくわかりません。上記の私の試みはコンパイルさえしません。

正しい方向へのヘルプやポインタは大きな助けになります。

4

1 に答える 1