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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T20:54:55+00:00 2026-06-13T20:54:55+00:00

I am trying to get the total comments for an entity yet I am

  • 0

I am trying to get the total comments for an entity yet I am getting back incorrect results.

How would I get a Task and its comments counts (eagerly loaded)

        var tasks = _session.QueryOver<Task>(() => taskAlias)
                                 .Where(x => x.OrganizationID == null)
                                 .Fetch(x => x.AssignedUser).Eager
                                 .Fetch(x => x.Owner).Eager
                                 .Fetch(x => x.Comments).Eager
                                 .List();

This returns:

Task.ID 1 Comments 3
Task.ID 1 Comments 3
Task.ID 1 Comments 3

Task.ID 2 Comments 2
Task.ID 2 Comments 2

Task.ID 3 Comments 1

I want:

Task.ID 1 Comments 3

Task.ID 2 Comments 2

Task.ID 3 Comments 1

My fluent mappings are:

HasMany(x => x.Comments).Table("tComments").ForeignKeyConstraintName("fT_Task_ID").KeyColumn("fC_Resource_ID").Where("fC_Type = 'Task'").ReadOnly();

  • 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-13T20:54:56+00:00Added an answer on June 13, 2026 at 8:54 pm

    If I understand your issue correctly, the problem is that your getting the correct data back, it’s just duplicating at the root level. If this is the case, change your query to:

    var tasks = _session.QueryOver<Task>(() => taskAlias)
                                     .Where(x => x.OrganizationID == null)
                                     .Fetch(x => x.AssignedUser).Eager
                                     .Fetch(x => x.Owner).Eager
                                     .Fetch(x => x.Comments).Eager
                                     .TransformUsing(new DistinctRootEntityResultTransformer())
                                     .List();
    

    When you have an entity and it contains a collection of entities and you tell NHibernate to fetch the collections eagerly the SQL that is generated will essentially return as:

    TASK 1 - COMMENTS 1A
    TASK 1 - COMMENTS 1B
    TASK 1 - COMMENTS 1C
    TASK 2 - COMMENTS 2A
    TASK 2 - COMMENTS 2B
    ...
    

    The DistinctRootEntityResultTransformer is what we use to tell NHibernate that the root element should be unique. As your original code didn’t have the transformer your root elements are duplicated.

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

Sidebar

Related Questions

I'm trying to get total salary for the whole company by: NSNumber *totalSalary =
I'm trying to get the total of calc.transport Table 3_product_folder contains duplicate values (column
I'm trying to find a way to get the total number of child nodes
basically I am trying to get the total of (facebook) likes for an external
I am trying to get a total record count from the below Method using
I'm trying to get the total amount of Milliseconds ( not the millis field)
The main problem I'm having is trying to get the total wins loses and
I'm trying to figure out a way in Wordpress to get the total number
I'm trying to get the total count of facebook likes for links. paste the
I am trying to get a total of 25 associations from the database. I

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.