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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:41:00+00:00 2026-05-11T10:41:00+00:00

I have a User, Book and UserBooks releation table. UserBooks table like this |UserID

  • 0

I have a User, Book and UserBooks releation table. UserBooks table like this

|UserID | BookID  | Status    |    1        34      Read    1        35      Unread     2        34      Read    2        70      Read    2        32      Unread      ................... 

My domain classes are User,Book and UserBook. in NHibernate how can I get top 10 most read books and their read count by users?

Top 10 Read Books

| BookID | ReadCount |    34         2    70         1    ............... 
  • 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. 2026-05-11T10:41:01+00:00Added an answer on May 11, 2026 at 10:41 am

    Assuming you are using composite-element to map your UserBook class:

    var top10Books = session     .CreateQuery(@'select b.Book                     from User u                     join fetch u.Books b                     where b.Status = :status')     .SetParameter('status', 'Read')     .SetMaxResults(10)     .SetResultTransformer(CriteriaSpecification.DistinctRootEntity)     .List<Book>(); 

    And here’s the link to the complete source code.

    EDIT:

    I see that you require the number of times a book has been read. Here’s the query:

    var top = session     .CreateQuery(@'select b.Book, count(b.Book.Id)                     from User u join fetch u.Books b                     where b.Status = :status                     group by b.Book')     .SetParameter('status', 'Read')     .SetMaxResults(10)     .List<object[]>();      foreach (var item in top)     {         var book = (Book)item[0];         var readCount = (long)item[1];         Console.WriteLine('book id: {0}, read count: {1}', book.Id, readCount);     } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say I have a model like this: class Book(models.Model): user = models.ForeignKey(User) book_isbn =
I have a model like this: class Book(models.Model): authors = models.ManyToManyField(User) # User is
I have 2 classes @Entity @Table(name = user) public class User @Id @Column(name =
I have 3 models such as User model,Book model, and Author model. I'd like
I have 2 models: User and Book and a join model ownership which connect
I have a book app. User choose a book and UITextView show it. Every
I have a simple rails application were book belongs_to user and user has_many book.
i have this code SELECT DISTINCT idx_campus_bookinfo,c.userid as Buyer,bookname,book_explain,writedate FROM campus_bookinfo cb LEFT JOIN
I have this user control: <%@ Control Language=C# AutoEventWireup=true CodeBehind=cite.ascx.cs Inherits=cite %> with behind
This is my model: class User {...} class Book { User author; int number;

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.