我如何在NHibernate中映射这个

时间:2009-03-30 18:33:11

标签: nhibernate fluent-nhibernate nhibernate-mapping

我有两个班,调查和民意调查班。我也有问题和问题选择课程。我如何映射这些,所以我提出了特定的表格格式。这是所涉及的课程。

public class Survey
{
     public IList<Question> Questions { get; private set; }   
}

public class Poll
{
    public Question Question { get; set; }
}

public class Question
{
    public string Text { get; set; }
    public IList<QuestionChocie> Choices { get; private set; }
}

public class QuestionChoice
{
    public string Text { get; set; }
}

我正在拍摄的结果表格包括以下内容

Surveys- a table of survey information.
Polls - a table of polls information.
SurveyQuestions -a table of survey questions.
PollQuestions - a table of poll questions.
SurveyChoices - a table of the question choices for the surveys.
PollChoices - a table of the question choices for the survey.

最好,我真的想知道Fluent NHibernate,或者只是映射xml也很好。

1 个答案:

答案 0 :(得分:0)

你没有定义表之间的关系,所以我假设一对多。

一般映射是:

public class SurveyMap : ClassMap<Survey>
{
    public SurveyMap()
    {
        HasMany<SurveyQuestion>(x => x.Questions).Inverse();
        // Rest of mapping
    }
}

public class SurveyQuestionMap : ClassMap<Question>
{
    public QuestionMap()
    {
        References<Survey>(x => x.Survey);
        HasMany<SurveyChoice>(x => x.Choices).Inverse();
        // Rest of mapping
    }
}

public class SurveyChoiceMap : ClassMap<SurveyChoice>
{
    public SurveyChoiceMap()
    {
        References<SurveyQuestion>(x => x.Question);
        // Rest of mapping
    }
}