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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:54:43+00:00 2026-05-13T18:54:43+00:00

I am trying to efficiently work with parent & child (post & tags) entities.

  • 0

I am trying to efficiently work with parent & child (post & tags) entities. A sample of the code can be seen here: http://gist.github.com/297464

Using the following results in less than 10 distinct Post entities if any of Post contains more than 1 tag.

var posts = session
    .CreateCriteria<Post>()
    .SetMaxResults(10)
    .SetFetchMode("Tags", FetchMode.Eager)
    .List<Post>();

If I remove the .SetFetchMode line above, I get the 10 records I am looking for, but all of the Tag entities are queried and then filtered in memory.

It seems like I should be able to instruct NHiberate to either pass in a list of PostIds or do a join.

I am pretty new to NHiberate so it is also entirely possible I am going at this completely wrong.

Thanks,
Scott

  • 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-13T18:54:44+00:00Added an answer on May 13, 2026 at 6:54 pm

    The problem is that SetMaxResults is not applied to the number of root entities returned from the query, it is translated into a T-SQL TOP (in the case of SqlServer), which is applied to the result from a join query. Since there is one row in the result set for each child of a root entity the TOP will not have the desired effect.

    To achieve a limit on the number of root entities you could use a join query with a subquery that contains the SetMaxResults limit.

    // Select the ids of the first ten posts
    var subquery = DetachedCriteria.For<Post>()
        .SetMaxResults(10)
        .SetProjection(Projections.Property("Id"));
    
    // Do a join query with posts and tags, for the posts who's ids are
    // in the result of the subquery
    var posts = session.CreateCriteria<Post>()
        .SetFetchMode("Tags", FetchMode.Join)
        .Add(Subqueries.PropertyIn("Id", subquery))
        .SetResultTransformer(Transformers.DistinctRootEntity)
        .List<Post>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 318k
  • Answers 318k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer A one-to-one relationship is a unique relation between two entities… May 13, 2026 at 11:51 pm
  • Editorial Team
    Editorial Team added an answer (1) Asp.Net Accordion is obviously SEO friendly but it lot's… May 13, 2026 at 11:51 pm
  • Editorial Team
    Editorial Team added an answer Your problem is that you're not actually sending SMS messages,… May 13, 2026 at 11:51 pm

Related Questions

I have a parent Div : <div id=ctl00_MainContentAreaPlaceHolder_deliveryOpen class=delivery_open style=display: block;> //Child select Element
I am currently trying to find the parent of a parent of an element.
I am trying to figure out exactly what these new fangled data stores such
We have an ASP.Net application that provides administrators to work with and perform operations
I have a stream object, and I want to create and output xml using

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.