0

I have following database and I want to create mapping in Fluent nhibernate so that I can traverse object collection like

survey.question.feedback to get all responses to questions .. how can I do that?

Database design

I have following mapping so far

 public class SurveyMapping : ClassMap<Survey>
{
    public SurveyMapping()
    {
        Id(x => x.Id, "SurveyId");
        Map(x => x.Name);
        Map(x => x.Type);
        Map(x => x.CreationDate);
        Map(x => x.ModificationDate);
        HasManyToMany<SurveyQuestions>(x => x.Questions).Table("Survey-Questions")
            .ParentKeyColumn("SurveyId").ChildKeyColumn("QuestionId").Cascade.All();
        HasManyToMany<User>(x => x.Users).Table("User-Surveys").ParentKeyColumn("SurveyId").ChildKeyColumn("UserId").Cascade.None();
    }
}

public class SurveyQuestionsMapping : ClassMap<SurveyQuestions>
{
    public SurveyQuestionsMapping()
    {
        Table("Questions");
        Id(x => x.Id, "QuestionId");
        Map(x => x.QuestionText);
        Map(x => x.CommentText);
        Map(x => x.Type);
        Map(x => x.Scale);
        Map(x => x.Rating);
        Map(x => x.Threshold);
        Map(x => x.CreationDate);
        Map(x => x.ModificationDate);
        HasMany<UserSurveyFeedback>(x => x.Feedback)
            .KeyColumn("QuestionId");
        **// This is the confusing part How I can load feedback associated with specific user here**
    }
}
Community
  • 1
  • 1
Paresh
  • 993
  • 1
  • 7
  • 15

1 Answers1

0

You should have many-to-many relations from User to Survey, from User to Feedback, from Question to Survey and from Question to Feedback. As for querying all feedback from a user, it is simple:

var feedbackFromUser = session.Query<Feedback>().Where(f => f.User.UserID == userID).ToList();
Ricardo Peres
  • 13,724
  • 5
  • 57
  • 74
  • Thank you Ricardo for your reply. I am not sure how can I create many to many mapping from user to feedback and question to feedback as I need to consider the combination of (surveyID, QuestionID, UserID) columns from feedback table – Paresh Jul 10 '14 at 15:38
  • Also I need the feedback from user for particular survey and question.. something like User.Survey[0].Question[0].Feedback – Paresh Jul 10 '14 at 15:44
  • It´s pretty straightforward without FNH. Give me a day and I'll try to come up with a working example. – Ricardo Peres Jul 10 '14 at 16:28