質問と回答の間に多対多の関係があります。しかし今、有効な質問と回答のペアにコストを追加したいと考えています。元のプロパティへのすべての参照を変更する必要がないようにする方法を考えようとしていました。出来ますか?
public class Question
{
public int ID { get; set:}
public string Text { get; set; }
//The original many-to-many
//public virtual ICollection<Answer> Answers { get; set; }
//but now I need a QuestionAnswerPair as an entity
//problem is that Adding or Removing does not affect the QuestionAnswerPairs collection
[NotMapped]
public ICollection<Answer> Answers
{
get
{
return QuestionAnswerPairs.Select(x => x.Answer).ToList();
}
}
public virtual ICollection<QuestionAnswerPair> QuestionAnswerPairs { get; set; }
}
public class Answer
{
public int ID {get; set;}
public string Text { get; set; }
//The original many-to-many
//public virtual ICollection<Question> Questions { get; set; }
}
//UnitCosts should only be added to valid Question-Answer pairs
//so I want to have a cost linked to the many-to-many relationship
public class QuestionAnswerPair
{
public int ID {get; set;}
public int AnswerID { get; set; }
public virtual Answer Answer { get; set; }
public int QuestionID { get; set; }
public virtual Question Question { get; set; }
public decimal? Amount { get; set; }
}