0

我有两个课程,Survey 和 Poll 课程。我也有问题和问题选择课程。我如何映射这些,以便得出特定的表格格式。以下是所涉及的课程。

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 也可以。

4

1 回答 1

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
    }
}
于 2009-03-30T18:54:45.330 回答