Fluent NHibernate - 将两个一对多映射到同一实体的最佳方法是什么
我需要一些帮助来使用 Fluent NHibernate 映射以下结构。我的课程背后的逻辑是提出一个包含一系列选项和一个答案的问题。每个答案都包含问题所包含选项的子列表。我希望下面的代码更清晰
我已经最小化了每个类的代码,以仅包含与该问题相关的数据
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; }
}
这里的问题是如何映射答案类的选择列表,以便答案中的选择在问题中引用相同的选择,
如果你们有更好的主意,我也愿意接受建议,甚至改变类结构以实现相同的目标,
提前致谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信您的类将完全按照您设计的那样自动映射。
然后,您可以填充您的选择列表,在需要的地方使用相同的选择,一切都应该正常工作。
编辑:
请访问此链接获取自动映射文档。
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.