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 7493005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:42:07+00:00 2026-05-29T16:42:07+00:00

Assume I had these tables in my database that is queried by a web

  • 0

Assume I had these tables in my database that is queried by a web service (WCF) via NHibernate:

Table "Patients"
  Column "Id"
  Column "LastName"
  Column "FirstName"
  Column "Age"

Table "Treatments"
  Column "Id"
  Column "PatientId"
  Column "Name"
  Column "IsActive"

A patient can have any number of treatments. If I wanted to gather a list of patients with their currently active treatments, how could I most efficiently achieve that in NHibernate?

Currently, I’m doing this (with SetFirstResult() and SetMaxResults(), of course):

var patientsWithTreatments = new List<PatientWithTreatments>();

var patients = Session.CreateCriteria<Patient>().List<Patient>();
foreach(Patient patient in patients) {
  patientsWithTreatments.Add(
    new PatientWithTreatments(patient) {
      Treatments = Session.CreateCriteria<Treatment>()
        .Add(Restrictions.Eq("PatientId", patient.Id)).List<Treatment>()
    }
  );
}

Which involves a round-trip to the database per patient in the result set, which is a pretty bad idea. Is there some magic with plain NHibernate queries or will I have to use HQL (which I don’t have a firm grasp of yet) 🙂

  • 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-05-29T16:42:08+00:00Added an answer on May 29, 2026 at 4:42 pm

    NHibernate has the option to add relationships behind the scenes (meaning they’re known to NHibernate but not exposed to code) via access="noop" in the mapping file.

    These can then supposedly be used like any normally declared relationship in HQL.

    As of NHibernate 3.1.0, for me this had the slightly inconvenient side-effect of completely deleting all of the referenced rows from the other table right when the query is run, so you might want to double-check before using access="noop" in production code.

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

Sidebar

Related Questions

For the sake of simplicity, let's assume the following tables exist: Table 1 -
Let's assume I two tables GOOD and BAD that stores records for widget production.
I had assume I could just do this, but I don't have a way
I had assumed that the canonical form for operator+, assuming the existence of an
I assumed that the C# margin property had a meaning like in CSS -
(assume php5) consider <?php $foo = 'some words'; //case 1 print these are $foo;
Assume a table structure of MyTable(KEY, datafield1, datafield2...) . Often I want to either
Assume that we have N erlang nodes, running same application. I want to share
I am new to ADO.net and have this problem: Let's assume I have these
I have the following database table with information about people, diseases, and drugs: PERSON_T

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.