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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:35:07+00:00 2026-06-08T11:35:07+00:00

I’m currently trying to get (Fluent)NHibernate to map an object to our legacy database

  • 0

I’m currently trying to get (Fluent)NHibernate to map an object to our legacy database schema. There are three tables involved.

  • Table a contains most information of the actual object I need to retrieve
  • Table b is a table which connects table a with table c
  • Table c has one additional field I need for the object

An SQL query to retrieve the information looks like this:

SELECT z.ID, z.ZANR, e.TDTEXT 
FROM   PUB.table_a z 
JOIN   PUB.table_b t ON (t.TDKEY = 602) 
JOIN   PUB.table_c e ON (e.ID = t.ID AND e.TDNR = z.ZANR) 
WHERE  z.ZANR = 1;

The main problem is how to specify these two join conditions in the mapping.

Entity for table a looks like this:

public class EntityA
{
    public virtual long Id { get; set; }
    public virtual int Number { get; set; }
    public virtual string Name { get; set; }
}

Name should map to the column table_c.TDTEXT.

The mapping I have so far is this:

public class EntityAMap : ClassMap<EntityA>
{
    public EntityAMap()
    {
        Table("PUB.table_a");
        Id(x => x.Id).Column("ID");
        Map(x => x.Number).Column("ZANR");
    }
}

I tried to map the first join with the same strategy as in How to join table in fluent nhibernate, however this will not work, because I do not have a direct reference from table_a to table_b, the only thing connecting them is the constant number 602 (see SQL-query above).

I didn’t find a way to specify that constant in the mapping somehow.

  • 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-06-08T11:35:08+00:00Added an answer on June 8, 2026 at 11:35 am

    you could map the name as readonly property easily

    public EntityAMap()
    {
        Table("PUB.table_a");
    
        Id(x => x.Id).Column("ID");
    
        // if ZANR always has to be 1
        Where("ZANR = 1");
    
        Map(x => x.Number).Column("ZANR");
        Map(x => x.Name).Formula("(SELECT c.TDTEXT FROM PUB.table_b b JOIN PUB.table_c c ON (c.ID = b.ID AND b.TDKEY = 602 AND c.TDNR = ZANR))");
    }
    

    Update: i could only imagine a hidden reference and the name property delegating to there

    public EntityAMap()
    {
        HasOne(Reveal.Member<EntityA>("hiddenEntityC"));
    }
    
    public class EntityB
    {
        public virtual int Id { get; set; }
        public virtual EntityA EntityA { get; set; }
    }
    
    public EntityCMap()
    {
        Where("Id = (SELECT b.Id FROM PUB.table_b b WHERE b.TDKEY = 602)");
    
        References(x => x.EntityA).PropertyRef(x => x.Number);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I know there's a lot of other questions out there that deal with this

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.