Fluent NHibernate - What's the best way to have two one-to-many mappings to the same entity
I need a little help to map the following structure using Fluent NHibernate. The logic behind my classes is to have a question that contains a list of choices and one answer. Each answer contains a sub-list of the choices contained by the question. I hope the code below is more clear
I've minimized the code for each class to contain only the data relevant to this question
class Question {
public virtual int Id { get; set; }
public virtual IList<Choice> Choices { get; set; }
public virtual Answer Answer { get; set; }
}
class Choice {
public virtual int Id { get; set; }
public virtual Question Question { get; set; }
}
class Answer {
public virtual int Id { get; set; }
public virtual IList<Choice> Choices { get; set; }
}
The issue here is how to map the list of choices for the Answer class, so that a choice in the answer will reference the same choice in the question
I'm opened also to suggestions to even change the class structure to achieve the same goal, if you guys have a better idea
Thanks in 开发者_运维问答advance
I believe your classes will Automap exactly as you've designed them.
Then, you can just populate your Choices lists, with the same Choice in both of them where desired, and everything should just work.
Edit: Go to this link for Automapping documentation.
精彩评论