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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:41:46+00:00 2026-05-15T10:41:46+00:00

how do we do this mapping but fluently? <class name=Person table=People> <id name=Id> <generator

  • 0

how do we do this mapping but fluently?

<class name="Person" table="People">

    <id name="Id">
        <generator class="identity"/>
    </id>

    <property name="Name" />

    <join table="Addresses">
        <key column="PersonId"/>
        <property name="Line1"/>
        <property name="Line2"/>
        <property name="City"/>
        <property name="Country"/>
        <property name="ZipCode"/>
    </join>

</class>

I know i can use ‘References’ but i don’t need all the columns from the related table. i just need one property.

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

    What Paco said is not right. This can be done in Fluent NHibernate.
    I searched the web myself quite a while, couldn’t find anyone talking about this option, so I just played around with FNHibernate a little and finally managed to do it.

    This was my scenario :

    I have two tables –

    "FormFields" => Columns { "FieldId", "FieldName", "FieldType", "DisplayOrder" }
    "FormStructure" => Columns { "FormId", "FormType", "FieldId" }
    

    These were my entities :

    public class FormStructure
    {
        public virtual Int32 FormId { get; private set; }
        public virtual Int32 FormType { get; set; }
        public virtual FormField FieldId { get; set; }
    }
    
    public class FormField
    {
        public virtual int FieldId { get; private set; }
        public virtual String FieldName { get; set; }
        public virtual int? FieldType { get; set; }
        public virtual int? DisplayOrder { get; set; }
    }
    

    I have a couple of methods in my query that return a list of FormStructure objects. I wanted these methods to give me them ordered by the DisplayOrder field in the FormField object, and wanted the DisplayOrder available as a property in my FormStructure object for other reasons as well.

    This basically means I needed to join the tables so that I would retrieve all the columns from the FormStructure table along with the DisplayOrder column from the FormField table, joining them on the matching FieldId columns.

    What I did to solve this :

    1. I added a property called DisplayOrder to my FormStructure object.

      public virtual int? DisplayOrder { get; set; }
      
    2. I added the Join method to my FormStructure mapping class so it looked like this.

      public class FormStructureMap : ClassMap<FormStructure>
      {
          public FormStructureMap()
          {
              Table("FormStructure");
      
              Id(x => x.Id);
              Map(x => x.FormType);
              References(x => x.Schedule).Column("ScheduleId");
              References(x => x.Field).Column("FieldId");
              Map(x => x.IsMandatory).Nullable();
      
              Join("FormFields", m =>
              {
                  m.Fetch.Join();
                  m.KeyColumn("FieldId");
                  m.Map(t => t.DisplayOrder).Nullable();
              });
          }
      }
      

    The Join method will obviously join between the two tables on the column you defined in the KeyColumn method within the Join.

    This will also remove some of the rows that have null values. In order to avoid this (I ran into this recently) you can add m.Optional(); inside the Join method.

    I could now retrieve a list of FormStructure objects, order them by DisplayOrder and even have DisplayOrder available as a property in the FormStructure object.

    return session.CreateCriteria<FormStructure>()
                  .Add(Expression.Eq("FieldName", fieldName))
                  .AddOrder(Order.Asc("DisplayOrder"))
                  .List<FormStructure>();
    

    This couldn’t have been done before, because it wouldn’t have recognized the DisplayOrder column in the Order clause I have there.

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

Sidebar

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.