Как мне сопоставить это в NHibernate

У меня два класса: опрос и опрос. Также у меня есть классы «Вопрос» и «Выбор вопроса». Как мне их сопоставить, чтобы я выбрал определенные форматы таблиц. Вот участвующие классы.

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 тоже подойдет.


person Community    schedule 30.03.2009    source источник


Ответы (1)


Вы не определили отношения между таблицами, поэтому я предполагаю «один ко многим».

Общее отображение будет следующим:

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
    }
}
person Stuart Childs    schedule 30.03.2009
comment
Стюарт, я думаю, вы можете поместить имена типов между ‹...›. Их следует предполагать, если я чего-то не упускаю. - person Dane O'Connor; 03.04.2009
comment
Вы правы, вы можете не использовать типы. Просто я предпочитаю оставить это, чтобы было понятно, что я отображаю. Мне нравится читать его как «Имеет много от X до Y» или «Ссылки с X по Z». - person Stuart Childs; 03.04.2009