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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:47:00+00:00 2026-05-23T10:47:00+00:00

I have a class that is many-to-one with its parent. I’d like to expose

  • 0

I have a class that is many-to-one with its parent. I’d like to expose the parent’s properties through the child without exposing the parent directly. I’d also like to query on and order by those properties.

Classes

public class Organization
{
    public virtual string Name { get; set; }
    public virtual bool IsNonProfit { get; set; }
}

public class Contact
{
    private Organization _organization;
    public virtual string OrganizationName 
        { get { return _organization.Name; } }
    public virtual bool OrganizationIsNonProfit 
        { get { return _organization.IsNonProfit; } }
}

Mapping

public class OrganizationMap : ClassMap<Organization>
{
    public OrganizationMap()
    {
        Map(x => x.Name);
        Map(x => x.IsNonProfit);
    }
}

public class ContactMap : ClassMap<Contact>
{
    public ContactMap()
    {
        References<Organization>(Reveal.Member<Contact>("_organization"))
            .Access.CamelCaseField();
    }
}

Query

public class Example
{
    private ISessionFactory _sessionFactory;

    public Example(ISessionFactory sessionFactory)
    {
        _sessionFactory = sessionFactory;
    }

    public IEnumerable<Contact> DoQuery(int forPage, int rowsPerPage)
    {
        using (var session = _sessionFactory.OpenSession())
        {
            return session.Query<Contact>().OrderBy(x => x.OrganizationName)
                .Skip((forPage - 1) * rowsPerPage).Take(rowsPerPage);
        }
    }
}

The problem is that this results in a “Could not resolve property: OrganizationName” error. It looks like I could map those fields with a formula, but then I’d end up with a sub-select for each field on a table that’s already joined into my query. Alternatively, I could wrap the Contact’s organization with a public getter and change my query to OrderBy(x => x.Organization.Name). That leaves me with a Law of Demeter violation though.

Am I off track? How should I handle this?

edited to show paging

  • 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-23T10:47:01+00:00Added an answer on May 23, 2026 at 10:47 am

    You can’t use non-mapped properties in queries. How should NHibernate know how to create a SQL condition for it? In your case it might be easy, but what if you’d have a call to a method or some complicated logic in that property?

    So yes, you need at least a public getter property.

    Alternatively, do the sorting in memory (after NHibernate has executed the query).

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

Sidebar

Related Questions

I have this code that uses a template parent class A that has one
I have a EF Code First One-To-Many relationship. It's essentially a Parent/Child relations as
I have a bi-directional one-to-many relationship defined between Parent and Child classes. I'm looking
I have a parent class called Exam and that has many instances of a
I have this class that has many class members, and a lot of different
In a C# Winforms (3.5) application I have added a class that contains many
I have a class that I can have many instances of. Inside it creates
I have a abstract base class that I have many inherited classes coming off
I have the problem that my view controller class has too many delegates and
I have a variable that I'm using many times in a class and as

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.