Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7979531
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T09:48:13+00:00 2026-06-04T09:48:13+00:00

Really trying to get my head around this but cannot see the light through

  • 0

Really trying to get my head around this but cannot see the light through the trees. Probably missed something obvious!

Within the database when I create the object it works within any issues but when I try to list the values, the linking is null…

There are two objects, Question and Response. A question can have many responses so here are the models:

public class Question
{
    public int Id { get; set; }
    public int QuestionNumber { get; set; }
    public string QuestionText { get; set; }
    public IList<Response> Responses { get; set; } 

    public Question()
    {
        Responses = new List<Response>();
    }
}

public class Response
{
    public int Id { get; private set; }
    public Question Question { get; set; }
    public int ResponseValue { get; set; }
    public string ResponseText { get; set; }
}

And here are the mappings:

public class QuestionMap : ClassMap<Question>
{
    public QuestionMap()
    {
        Id(q => q.Id);
        Map(q => q.QuestionNumber);
        Map(q => q.QuestionText).Length(300).Not.Nullable();
        HasMany<Response>(q => q.Responses).Inverse().AsBag();
    }
}

public class ResponseMap : ClassMap<Response>
{
    public ResponseMap()
    {
        Id(x => x.Id);
        References<Question>(x => x.Question).Not.Nullable();
        Map(x => x.ResponseText);
        Map(x => x.ResponseValue);
    }
}

So when I use

var responses = _session.CreateCriteria(typeof(Response)).List<Response>();

and debug and look at the Question object, it is always null.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T09:48:15+00:00Added an answer on June 4, 2026 at 9:48 am

    By default all relations in NHibernate are lazy. So you have two options. Set Not.LazyLoad() or Fetch strategy in your mapping for responses OR do the fetch when you are querying the database.

    var responses = _session.CreateCriteria(typeof (Response))
                    .SetFetchMode("Responses", NHibernate.FetchMode.Eager)
                    .List();
    

    you may need to set the fetching strategy in the mapping for responses when you use .SetFetchMode(…). Just play around with these two settings – one at a time or both

    PS: By the way I am confused how exactly not.lazyload and fetch are working and posted a question about that. FluentNHibernate: LazyLoad and Fetch

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Trying to merge two tables, but I can't really get my head around it.
I'm trying to wrap my head around this, but I seem to go in
i am really trying to do this but i am failing to find a
I'm really stuck trying to use java wrapper library for opencv's cvMatchTemplate. See this
I am poking at XBRL documents trying to get my head around how to
I am desperately trying to get my head wrapped around how to implement home
I'm trying to get my head around the dbpedia JSON schema and can't figure
I'm getting started with WPF and trying to get my head around connecting data
Been trying to find an answer to this but can't seem to get my
I'm trying to get my head around how one would unit test an ASP.NET

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.