【发布时间】:2011-11-29 19:45:08
【问题描述】:
我正在尝试将 NHibernate 与在概念上等同于以下内容的数据库一起使用:
CREATE TABLE Survey(ID int, SurveyName varchar(max))
CREATE TABLE Question(ID int, QuestionText varchar(max))
CREATE TABLE SurveyQuestion(SurveyID int, QuestionID int, Order int, Required bit)
CREATE TABLE AnsweredSurvey(ID int, SurveyID int, AnsweredBy varchar(max))
CREATE TABLE AnsweredQuestion(ID int, AnsweredSurveyID int, QuestionID int, Answer varchar(max))
每当用户进行调查时,AnsweredSurvey/AnsweredQuestion 表都会从模板表中填充。这是由另一个应用程序执行的,所以我只从这些表中读取数据。我无法控制数据或架构。
我遇到问题的实体是:
class AnsweredQuestion {
int Id;
AnsweredSurvey AnsweredSurvey;
SurveyQuestion SurveyQuestion;
}
请注意,它有一个 SurveyQuestion 类型的属性,而不是普通的 Question。我希望能够根据 AnsweredQuestion 的 QuestionID 和父 AnsweredSurvey 的 SurveyID 填充此属性。在 NHibernate 中是否有一种直接的方法可以以这种方式映射这些实体?我正在使用 FluentNHibernate,但纯 HBM 解决方案至少会为我指明正确的方向。
为完整起见,以下是其他实体:
class Survey {
int Id;
string SurveyName;
IEnumerable<SurveyQuestion> SurveyQuestions;
}
class Question {
int Id;
string QuestionText;
}
class SurveyQuestion {
Survey Survey;
Question Question;
int Order;
bool Required;
}
class AnsweredSurvey {
int Id;
Survey Survey;
IEnumerable<AnsweredQuestion> AnsweredQuestions;
}
感谢您的宝贵时间!
【问题讨论】:
标签: .net sql sql-server nhibernate fluent-nhibernate