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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T02:16:57+00:00 2026-05-21T02:16:57+00:00

Background I’m a bit confused by the result I’m getting from this NHibernate query:

  • 0

Background

I’m a bit confused by the result I’m getting from this NHibernate query:

var result = (List<RatingsLipper>)_session.CreateCriteria<RatingsLipper>()
                      .Add<RatingsLipper>(xx => xx.ShareClassId == shareClassId)
                      .List<RatingsLipper>();

where RatingsLipper has the following mapping:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="FTMS.Domain"
                   namespace="FTMS.Domain.Entities">

    <class mutable="false" name="RatingsLipper" table="LipperRating" schema="offline">

        <id name="Id" column="LipperRating_LipperId">
            <generator class="native"></generator>
        </id>

        <property name="ShareClassId" column="LipperRating_ShareClassId" />

        <property name="RatingDate" column="LipperRating_RatingDate" />
        <property name="TimePeriod" column="LipperRating_RatingTimePeriodYears" />
        <property name="TotalReturn" column="LipperRating_TotalReturn" />
        <property name="ConsistentReturn" column="LipperRating_ConsistentReturn" />
        <property name="Preservation" column="LipperRating_Preservation" />
        <property name="Expense" column="LipperRating_Expense" />

    </class>
</hibernate-mapping>

The query produces the following SQL:

SELECT this_.LipperRating_LipperId             ,
       this_.LipperRating_ShareClassId         ,
       this_.LipperRating_RatingDate           ,
       this_.LipperRating_RatingTimePeriodYears,
       this_.LipperRating_TotalReturn          ,
       this_.LipperRating_ConsistentReturn     ,
       this_.LipperRating_Preservation         ,
       this_.LipperRating_Expense              
FROM   offline.LipperRating this_
WHERE  this_.LipperRating_ShareClassId = 19278 /* @p0 */

which in turn produces this table:

LipperRating_LipperId LipperRating_ShareClassId LipperRating_RatingDate LipperRating_RatingTimePeriodYears LipperRating_TotalReturn LipperRating_ConsistentReturn LipperRating_Preservation LipperRating_Expense
--------------------- ------------------------- ----------------------- ---------------------------------- ------------------------ ----------------------------- ------------------------- --------------------
60011179              19278                     2011-02-28 00:00:00.000 3                                  3                        2                             4                         0
60011179              19278                     2011-02-28 00:00:00.000 5                                  3                        3                             5                         0
60011179              19278                     2011-02-28 00:00:00.000 10                                 5                        4                             5                         0
60011179              19278                     2011-02-28 00:00:00.000 99                                 4                        4                             4                         0

The Problem

the problem I’m having is that the result I’m getting from the NHibernate query consists of 4 instances of the first row, and not the 4 different results we see in the tabular output from the SQL query.

Does this have something to do with the fact that the table LipperRating has a composite primary key? For reference, this table is defined as:

CREATE TABLE [offline].[LipperRating](
    [LipperRating_ShareClassId] [int] NOT NULL,
    [LipperRating_LipperId] [int] NOT NULL,
    [LipperRating_RatingDate] [datetime] NOT NULL,
    [LipperRating_RatingTimePeriodYears] [int] NOT NULL,
    [LipperRating_TotalReturn] [int] NULL,
    [LipperRating_ConsistentReturn] [int] NULL,
    [LipperRating_Preservation] [int] NULL,
    [LipperRating_Expense] [int] NULL,
 CONSTRAINT [LipperRatings_PK] PRIMARY KEY CLUSTERED 
(
    [LipperRating_ShareClassId] ASC,
    [LipperRating_LipperId] ASC,
    [LipperRating_RatingDate] ASC,
    [LipperRating_RatingTimePeriodYears] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

The Question

What do I need to do to get the correct results into my List<RatingsLipper>?

  • 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-21T02:16:58+00:00Added an answer on May 21, 2026 at 2:16 am

    I figured it out, with the help of: http://dotnetslackers.com/Community/blogs/antrad/archive/2008/02/10/how-to-map-composite-key-in-nhibernate.aspx

    I needed <composite-id>

    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                       assembly="FTMS.Domain"
                       namespace="FTMS.Domain.Entities">
    
        <class mutable="false" name="RatingsLipper" table="LipperRating" schema="offline">
            <composite-id>
                <key-property name="Id" column="LipperRating_LipperId" />
                <key-property name="ShareClassId" column="LipperRating_ShareClassId" />
                <key-property name="RatingDate" column="LipperRating_RatingDate" />
                <key-property name="TimePeriod" column="LipperRating_RatingTimePeriodYears" />
            </composite-id>
    
            <property name="TotalReturn" column="LipperRating_TotalReturn" />
            <property name="ConsistentReturn" column="LipperRating_ConsistentReturn" />
            <property name="Preservation" column="LipperRating_Preservation" />
            <property name="Expense" column="LipperRating_Expense" />
        </class>
    </hibernate-mapping>
    

    and I also had to add this to my RatingsLipper type:

    public override bool Equals(object obj)
    {
        bool equals = false;
    
        if (null != obj)
        {
            RatingsLipper temp = obj as RatingsLipper;
            if (null != temp)
            {
                equals = (this.ShareClassId == temp.ShareClassId 
                    && this.TimePeriod.Equals(temp.TimePeriod) 
                    && this.Id.Equals(temp.Id)
                    && this.RatingDate.Equals(temp.RatingDate));
            }
        }
    
        return equals;
    }
    
    public override int GetHashCode()
    {
        int hash = 1122; // no idea of the significance of this number!
    
        hash += (this.ShareClassId.GetHashCode());
        hash += (this.TimePeriod.GetHashCode());
        hash += (this.Id.GetHashCode());
        hash += (this.RatingDate.GetHashCode());
    
        return hash;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Background - I want to extract specific columns from a csv file. The csv
Background: This is a request for something that may not exist yet, but I've
BACKGROUND I am writing a screen capture application My code is based derived from
Background This is only my second PyQt4 project. Developing a Windows app that has
Background: I am getting a Internal Server 500 24 50 error after deploying an
Background Use Ajax to fire an event to the web server when a list
Background: I want to check-out the source code from Cliche , which is stored
background:transparent url(../img/fondo_footer.png) repeat-x scroll; background-position: 0px 140px; This way the background is vertically moved
Background : With a Python Script, I scraping data (html) from a Website and
Background: I have a little video playing app with a UI inspired by the

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.