0

Hibernate & NET Persistence API と C# を組み合わせて使用​​しています。2 つのエンティティ間に次の関係があります。

public class Question
{
    [OneToMany(Cascade = new CascadeType[] { CascadeType.ALL }, Fetch = FetchType.LAZY, MappedBy = "Question")]
    public virtual List<QueueLog> QueueLogs { get; set; }    
}

public class QueueLog
{
    [ManyToOne (Fetch = FetchType.EAGER, TargetEntity = typeof(Question))]
    [Column(Name = "question_id", Nullable = false)]
    public virtual List<Question> Question { get; set; }
}

しかし、主キー ID で質問をフェッチしているときに、次のエラーが発生します。

Missing column: Question_0 in Kmasters.dbo.queue_log
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: NHibernate.HibernateException: Missing column: Question_0 in Kmasters.dbo.queue_log

また、次の方法で2つのエンティティ間の関係を作成しようとしました:

public class Question
{
    [OneToMany(Cascade = new CascadeType[] { CascadeType.ALL }, Fetch = FetchType.LAZY)]
    [JoinColumn(Name = "question_id", ReferencedColumnName = "id")]
    public virtual List<QueueLog> QueueLogs { get; set; }    
}

public class QueueLog
{
    [ManyToOne (Fetch = FetchType.EAGER, TargetEntity = typeof(Question))]
    [Column(Name = "question_id", Nullable = false)]
    public virtual List<Question> Question { get; set; }
}

それでも同じエラーが発生します。誰でも私にこれに対する解決策を提案できますか?

4

1 に答える 1

0

次の変更を加えてコードを修正しました。

public class Question
{
   [OneToMany(TargetEntity = typeof(QueueLog), MappedBy = "question", Fetch = FetchType.EAGER, Cascade = new CascadeType[] { CascadeType.ALL })]
   public virtual NHibernate.Collection.PersistentBag QueueLogs { get; set; }
}

public class QueueLog
{
     [ManyToOne (Fetch = FetchType.EAGER, TargetEntity = typeof(Question))]
     [JoinColumn(Name = "question_id")]
     public virtual Question question { get; set; }
}
于 2012-11-01T11:44:58.357 に答える