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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T16:21:18+00:00 2026-05-22T16:21:18+00:00

Kindly consider this simplified scenario: Two NHibernate Entities: public class Foo { public virtual

  • 0

Kindly consider this simplified scenario:

Two NHibernate Entities:

public class Foo {
  public virtual Bar Bar {get; set;}
}

public class Bar {
  public virtual string Name {get; set;}
}

I need to sort a collection of Foo by their’s Bar’s name. however, not all Foos have Bars assigned. For some entities it is null

The obvious:

Foos.OrderBy(f => f.Bar.Name)

Throws an Exception.

The only way I can think of to handle it is to add a formula to Foo that I can use in the OrderBy clause. I have a feeling that there got to be a better and more elegant solution.

Any ideas?

Update

This issue is fixed in NHibernate 3.1 – https://nhibernate.jira.com/browse/NH-2412

The outer join for the OrderBy is "Built In"

  • 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-22T16:21:19+00:00Added an answer on May 22, 2026 at 4:21 pm

    You need to specify a join to Bar

    If you’re using NHibernate >=3.0.

    from foo in session.Query<Foo>()
    join bar in session.Query<Bar>() on foo.Bar.Id equals bar.Id into leftJoinFooBar
    from bars in leftJoinFooBar.DefaultIfEmpty()
    orderby bars.Name
    select foo
    

    if you/re using NHibernate <3.0. You’ll have to use Criteria or HQL.

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

Sidebar

Related Questions

Could someone kindly help me get this parsed. I have the following XML. I
I'm very new to js so kindly help me with this. I am trying
I am new to this field. So kindly go easy on me. I have
If this is answered somewhere else, kindly smack me and point me in the
Kindly get me the limits of following things in sqlite of iphone No of
Can someone kindly explain how the following python code is working? This code is
Kindly look at the following code: <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd>
I'm puzzled here, and kindly request your help. VC2005SP1 swallows this (stripped out) code
I need to get substed drive letter in Perl. Could anyone kindly help me?
Kindly need your help as this really taking me long time to try. From

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.