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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:03:30+00:00 2026-06-01T00:03:30+00:00

I have a search-method which returns multiple items, each with several child-properties with references

  • 0

I have a search-method which returns multiple items, each with several child-properties with references to other tables.
For the child-property that is a collection everything works as I want it to but how can I do the same for the one-to-one children?

Here is some stubs and some of the code I tried:

public class Request {
    //HasMany(x => x.Examinations).Access.CamelCaseField().Cascade.All().BatchSize(100);
    public virtual IList<Examination> Examinations;

    //References(x => x.Creator, "rem_creator_userid");
    public virtual User Creator { get; private set; }
}

public class RepositoryExample {

    // This search will ask one nice-looking query to the database fetchning all the
    // requests
    // Then it will ask ONE query fetching the Examinations from the database
    // Then it will ask N+1 questions fetching Creator from all Requests
    public IList<Request> Search1(ListRequestSearchConditions searchConditions) {
        var query =
            from request in Session.Query<Request>()
            from exam in request.Examinations
            where
                searchConditions.Units.Contains(request.ReferralSource) &&
                exam.Status.HasValue &&
                exam.Status.Value >= ExaminationStatus.Value.RequestSubmitted &&
                request.PatientId != null
            select request;

        return query
            .Skip((searchConditions.Page - 1) * searchConditions.PageSize)
            .Take(searchConditions.PageSize)
            .ToList();
    }

    // This search with ask one slow join-query fetching everything from the database
    public IList<Request> Search2(ListRequestSearchConditions searchConditions) {
            Examination examinationAlias = null;

        return Session.QueryOver<Request>()
            .WhereRestrictionOn(request => request.ReferralSource).IsIn(searchConditions.Units)
            .Where(request => request.PatientId != null)
            .JoinAlias(request => request.Examinations, () => examinationAlias)
            .Where(() => examinationAlias.Status.Value != null)
            .Where(() => examinationAlias.Status.Value >= ExaminationStatus.Value.RequestSubmitted)
            .Skip((searchConditions.Page - 1) * searchConditions.PageSize)
            .Take(searchConditions.PageSize)
            .ToList();
    }

    // This search will first ask ONE query joining Request with Examinations
    // Then it will ask ONE query fetching the Examinations from the database
    // Then it will ask N+1 queries fetching Creator from all Requests
    public IList<Request> Search3(ListRequestSearchConditions searchConditions) {
            Examination examinationAlias = null;

        return Session.QueryOver<Request>()
            .WhereRestrictionOn(request => request.ReferralSource).IsIn(searchConditions.Units)
            .Where(request => request.PatientId != null)
            .JoinAlias(request => request.Examinations, () => examinationAlias)
            .Where(() => examinationAlias.Status.Value != null)
            .Where(() => examinationAlias.Status.Value >= ExaminationStatus.Value.RequestSubmitted)
            .Fetch(request => request.Examinations).Lazy
            .Fetch(request => examinationAlias.ExaminationType).Lazy;
            .Skip((searchConditions.Page - 1) * searchConditions.PageSize)
            .Take(searchConditions.PageSize)
            .ToList();
    }
}

I hope that is possible to do this in 3 queries, one fetching the list of Requests, one fetching the Examinations and one fetching the Creators.

  • 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-01T00:03:32+00:00Added an answer on June 1, 2026 at 12:03 am

    If you don’t want to have it in one single query (using Fetch/ThenFetch in LINQ) and use batching instead, you have to specify it at Creator mapping level. Batch size can’t be defined at query level.

    In Fluent NHibernate you can just add BatchSize(100) in your Creator mapping.

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

Sidebar

Related Questions

I have a search that returns JSON, which I then transform into a HTML
I have a search method that takes in a user-entered string, splits it at
I have implemented the search method for a UITableView populate from a NSArray (mylist):
I have a datatable with as search fields. I want a method on the
I have a LINQ method for the Search page of an in house app.
I have a DAO with a method CommitmentListDAO.getListByOwnerBadge that returns an arraylist of commitment
I'm consuming a webservice from another company, they have multiple versions running, each newer
I have a corpus of token-index based documents which offers a query method. The
I have a partial which returns results from the Amazon-ecs API (searches for books).
I have a class which contains this method /** * Uses the native RegExp

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.