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

  • Home
  • SEARCH
  • 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 6017399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:07:22+00:00 2026-05-23T03:07:22+00:00

I have an entity that maps to a table called Rule. The table for

  • 0

I have an entity that maps to a table called Rule. The table for this entity has an FK to another Table called Category. I’m trying to figure out how to pull in a property from Category in my Rule entity. I’m pretty sure I want to use a join in my entity mapping, but I can’t figure out how to configure it so that it works. Here is my mapping:

Join("Category", x => 
{
    x.Map(i => i.CategoryName, "Name");
    x.KeyColumn("CategoryId");
    x.Inverse();
});

Here is the SQL that it’s generating…

SELECT ...
FROM Rule rules0_ left outer join Category rules0_1_ on rules0_.Id=rules0_1_.CategoryId
WHERE ...

Here is the SQL that I want.

SELECT ...
FROM Rule rules0_ left outer join Category rules0_1_ on rules0_.CategoryId=rules0_1_.Id
WHERE ...

I can’t seem to find anything on the JoinPart that will let me do this. Subselect looks promising from the little bit of documentation I’ve found, but I can’t find any examples of how to use it. Any advice on this problem would be much appreciated. Thanks!

  • 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-23T03:07:23+00:00Added an answer on May 23, 2026 at 3:07 am

    “Join” is poorly named. a “join” in an NHibernate mapping implies a zero-to-one relationship based on a relation of the primary keys of the two tables. You would use a join if, for instance, you had a User table and a UserAdditionalInfo table, with zero or one record per User. The UserAdditionalInfo table would likely reference the PK from User as both a foreign key and its own primary key. This type of thing is common when a DBA has to religiously maintain a schema for a legacy app, but a newer app needs new fields for the same conceptual record.

    What you actually need in your situation is a References relationship, where a record has a foreign key relationship to zero or one other records. You’d set it up fluently like so:

    References(x=>Category)
        .Column("CategoryId")
        .Inverse()
        .Cascade.None();
    

    The problem with this is that Category must now be mapped; it is a separate entity which is now related to yours. Your options are to live with this model, to “flatten” it by making the entity reference private, changing the mapping to access the entity as such, and coding “pass-throughs” to the properties you want public, or by using a code tool like AutoMapper to project this deep domain model into a flat DTO at runtime for general use. They all have pros and cons.

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

Sidebar

Related Questions

I have an entity that maps to an external oracle table which is one
I have an entity that has a state table associated with it. The state
I have a POCO class called Attachment that maps to a table in SqlServer
I have an entity that has a collection in it. The collection is a
Imagine you have an entity that has some relations with other entities and you
Let's say we have an entity that has attributes att1 and att2, where att1
I have an entity class that has a property with an underlying db column
A have a JPA entity that has timestamp field and is distinguished by a
I have an entity class that has 10 fields. I am using MS Validation
In my core data model I have a Person entity that has a to

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.