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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T04:32:21+00:00 2026-05-18T04:32:21+00:00

I’m having trouble with a certain mapping. Let’s say I have three assessments that

  • 0

I’m having trouble with a certain mapping. Let’s say I have three assessments that all derive off a base Assessment:

public abstract class Assessment
{
    public abstract int DamageCostTotal { get; set; }
}

public class IndividualAssessment
{
    public virtual int DamageCostHouse { get; set; }
    public virtual int DamageCostCar { get; set; }
    public virtual int DamageCostBelongings { get; set; }
    public override DamageCostTotal
    {
        get { return DamageCostHouse + DamageCostCar + DamageCostBelongings; }
    }
}

public class BusinessAssessment
{
    public virtual int DamageCostBuilding { get; set; }
    public virtual int DamageCostGoods { get; set; }
    public virtual int DamageCostOther { get; set; }
    public override DamageCostTotal
    {
        get { return DamageCostBuilding + DamageCostGoods + DamageCostOther; }
    }
}

public class InfrastructureAssessment
{
    public virtual int DamageCostStructure { get; set; }
    public virtual int DamageCostEstimatedRepair { get; set; }
    public override DamageCostTotal
    {
        get { return DamageCostStructure + DamageCostEstimatedRepair; }
    }
}

In other words, the three assessment types, IndividualAssessment, BusinessAssessment, and InfrastructureAssessment, all have specific damage costs, but they all implement the base class’ DamageTotalCost in order to get one assessment’s total damage cost.

In my Fluent NHibernate mappings, I mapped each DamageCostTotal for each specific assessment:

// individual assessment
Map(x => x.DamageCostTotal)
    .Access.Readonly()
    .Formula("DamageCostHouse + DamageCostCar + DamageCostBelongings");
// the other two are mapped the same way, just with a different formula

This works great when I query over the specific assessment types:

Session.Query<IndividualAssessment>().OrderBy(x => x.DamageCostTotal);
Session.Query<BusinessAssessment>().OrderBy(x => x.DamageCostTotal);
Session.Query<InfrastructureAssessment>().OrderBy(x => x.DamageCostTotal);

But when I try to query over the base assessment type:

Session.Query<Assessment>().OrderBy(x => x.DamageCostTotal);

It generates the wrong SQL (cleaned up a bit for easier readability):

SELECT ...
    DamageCostHouse + DamageCostCar + DamageCostBelongings as formula0_0_,
    DamageCostBuilding + DamageCostGoods + DamageCostOther as formula1_0_,
    DamageCostStructure + DamageCostEstimatedRepair as formula2_0_,
    FROM [Assessment] this_
    ORDER BY DamageCostStructure + DamageCostEstimatedRepair

As you can see, it’s creating the formulas correctly, but when it does the ORDER BY, it only orders it by the InfrastructureAssessment properties and not the formulas. Does anyone know how to map the base DamageCostTotal so that this query will return the correct result?

  • 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-18T04:32:21+00:00Added an answer on May 18, 2026 at 4:32 am

    One solution would be to map DamageCostTotal in the base class. Create a column for DamageCostTotal in the table if there isn’t one. NHibernate won’t need to know about the formulas in this scenario, which is fine since the classes are already doing the heavy lifting.

    Your query should result in SQL similar to this…

    SELECT ..., this_.DamageCostTotal FROM Assessment this_ ORDER BY this_.DamageCostTotal
    
    • 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 have a French site that I want to parse, but am running into
this is what i have right now Drawing an RSS feed into the php,
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti

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.