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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:46:07+00:00 2026-06-15T08:46:07+00:00

I have a class graph which is similar to the one below. I am

  • 0

I have a class graph which is similar to the one below.

I am using this example since it is more simpler than explaining the domain that I am working on.

public class Cheque {

   public FinanceAccount Account {get;set;}

   public Customer customer {get;set;}

   public Branch Branch {get;set;}
}

A Cheque entity has ManyToOne relation with rest of the three entities.

The relations for now are NOT bi-directional.

How can write an effective Futures Query to fetch a list of Cheques so that I do not get N+1 for loading Account, Customer, Branch ?

I have tried using left joins but wanted to know if this can be done using simplified SQLs

  • 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-15T08:46:08+00:00Added an answer on June 15, 2026 at 8:46 am

    We can achieve required results (no N+1) – but Futures won’t be the correct NHibernate feature for that. We can use them, but the trick for fetching many-to-one entities is elsewhere (see below). Futures as stated here: http://ayende.com/blog/3979/nhibernate-futures mean:

    … Future() and FutureValue() essentially function as a way to defer query execution to a later date, at which point NHibernate will have more information about what the application is supposed to do, and optimize for it accordingly

    So we can put more queries into one batch. The queries could be for example set of queries resulting in:

    • total Cheque
    • first 20 Cheque projections
    • max amount withdrawn in a last week
    • etc.

    So, in this case, we can put “different” types of queries, into Future.

    But to fetch many-to-one entities without N+1 – we can use standard Criteria API. So even if these properties are mapped as lazy with select as a fetch:

    <many-to-one name="Account" class="FinanceAccount" column="AccountId" 
           lazy="proxy" fetch="select"/>
    

    this Criteria will create only one select with left joins:

    var list = session.CreateCriteria<Cheque>()
      .SetFetchMode("Account", NHibernate.FetchMode.Join)
      .SetFetchMode("customer", NHibernate.FetchMode.Join)
      .SetFetchMode("Branch", NHibernate.FetchMode.Join)
      .Future<Cheque>()
      // or
      // .List<Cheque>() ... will be the same right now
      ;
    

    This will result in only one SQL select statement, joining Cheque and its reference properties.

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

Sidebar

Related Questions

I have a class named Graph, in this class I have a member named
I have a class Grid which produces a graph paper like grid on in
I have a custom made class called Graph in which I use adjacency lists.
I have a data model which is similar to this: (in another project) ________________________________
I have a graph which will be fed using an external source. So far,
I have class Vertex{ Graph _graph; float x; float y; string key; //and some
I have a class Graph with two lists types namely nodes and edges I
I have Vertex template in vertex.h. From my graph.h: 20 template<class edgeDecor, class vertexDecor,
I have Class and Student objects. Both have collection of another as property. Which
I have class LegacyClass which inherits OldBaseClass. I'm considering a change to introduce a

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.