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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:46:47+00:00 2026-05-14T05:46:47+00:00

I think this is a moderately neophyte question. I’ve been using NHibernate/FluentNHibernate for about

  • 0

I think this is a moderately neophyte question. I’ve been using NHibernate/FluentNHibernate for about 6 months or so, and I think I have a fair grasp of the basics. Now I’m pushing a little bit beyond. I’m sure this is documented, but I’ve spent several hours now on Google, and haven’t quite figured it out.

I have simple class, call it Simple:

public class Simple
{ public string Name { get; set;}
  public string Desc { get; set; }
  public string Status { get; set;}
}

Status is actually constrained to be one of a small set of values: “ACTIVE”, “ON-HOLD”, and “CLOSED”. In the DB schema, I have a simple read-only table called RetrofitStatus:

CREATE TABLE [dbo].[RetrofitStatus](
[Status] [nvarchar](10) NOT NULL,
[SortOrder] [smallint] NOT NULL,
CONSTRAINT [PK_RetrofitStatus] PRIMARY KEY CLUSTERED 
(
    [Status] ASC
)

And there’s a Foreign-key constraint on the Simple table to make sure Status is in RetrofitStatus.

The purpose of the RetrofitStatus table is to include the SortOrder column so that I can do (in SQL)

SELECT * from Simple s join RetrofitStatus r on r.Status=s.Status ORDER BY r.SortOrder

and sort my results into a display order (e.g., all ACTIVE entries first, then ON-HOLD entries, then CLOSED entries, since I’m sorting on a logical order, not alphabetical or anything else easily recognize).

My question is, how do I model that object and relationship in FNH? I can add the SortOrder property to my Simple definition and a make a View that represents that, but what will happen when I try to insert new Simple objects into the table? Obviously, I don’t want to try to insert the SortOrder property. I think I need to use the NHib element somehow, but again, I’m not clear on where that needs to go, what happens on insert, and how to do it in Fluent?

I’m going to try experimenting with trial-and-error, but I thought that maybe somebody who knows what they’re doing (which I don’t) can point me in the right direction and save me some time. Thanks for your help.

  • 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-14T05:46:48+00:00Added an answer on May 14, 2026 at 5:46 am

    Assuming you had a Simple class modified as follows (I wasn’t sure what you were doing about a key):

    public class Simple
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string Desc { get; set; }
        public string Status { get; set; 
        public int SortOrder { get; set; }
    }
    

    you could map like this:

    public SimpleMap : ClassMap<Simple>
    {
        Id(x => x.Id).Unique().GeneratedBy.Native();
        Map(x => x.Name);
        Map(x => x.Desc);
        Join("RetrofitStatus", join =>
        {
            join.KeyColumn("Status") 
                .Map(x => x.Status);
            join.Map(x => x.SortOrder).Not.Insert();
        });
    }
    

    I haven’t tested this, but this is the gist of it.

    You can specify that a property cannot be inserted or updated by using Not.Insert() or Not.Update(), respectively in your mapping, or can be neither inserted nor updated by using ReadOnly().

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

Sidebar

Related Questions

I think this could be a very easy question for you. But I have
I think this is a simple and a silly question. I have included a
I think this question has been asked many a times but I've been searching
I think this may be a browser dependent question- Suppose I have 10 Javascript
I think this is a very simple question, so forgive me if it's been
(I think this is a pretty basic question on OOP, but unfortunately I wasn't
I think this is nearly impossible or very tricky. I'm using CriteriaBuilder, JPA 2.0,
I think this is mostly because I'm new to PHP OOP, but I have
This is question about MVC web-app architecture, and how it can be extended to
I think this might be best asked using an example: use strict; use warnings;

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.