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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T21:49:29+00:00 2026-05-12T21:49:29+00:00

I’ve always taken a data centric approach to web apps, and so the paradigm

  • 0

I’ve always taken a data centric approach to web apps, and so the paradigm change involved when taking a pure OO approach using ORMs is still not completely natural to me, and evey now and then something ostensibly simple is not obvious.

Can someone please point me into the right direction of how to correctly model this situation in an ORM (Specifically NHibernate).

The situation: There are many Users, Many Items, users may rate Items.

In a data centric/relational approach it would look like this (and be very easy!):

- Items Table
ItemID 
ItemName

- UserRatings Table
UserID 
ItemID 
Rating

- Users Table
UserID 
UserName

If you want to find out what rating your logged in user gave for a particular item, you just do a joined query.

However, it’s not obvious to me how to model this in a OO way when using an ORM. I beleive I need three domain classes: Item, UserRating, and User. Presumably I also need a collection of UserRatings in the Items class, and a collection of UserRatings in the User class. But how do I navigate to the corect UserRating, from a particular item which I have loaded (and of course this UserRating must be the one related to the user I’m interested in).

Can anyone clarify this for me?

Thanks

  • 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-12T21:49:29+00:00Added an answer on May 12, 2026 at 9:49 pm

    Your classes would look like the following

    public class User 
    {
        public virtual int UserId { get; set; }
        public virtual string UserName { get; set; }
        public virtual IList<UserRating> Ratings { get; set; }
    }
    
    public class Item 
    {
        public virtual int ItemId { get; set; }
        public virtual string ItemName { get; set; }
        public virtual IList<UserRating> Ratings { get; set; }
    }
    public class UserRating 
    {
        public virtual User User { get; set; }
        public virtual Item Item { get; set; }
        public virtual Int32 Rating { get; set; }
    }
    

    Your mapping file would look like

    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Test" namespace="Test" >
        <class name="User">
            <id name="UserId" >
                <generator class="native" />
            </id>
            <property name="UserName" />
            <bag name="Ratings" generic="true" inverse="true" table="UserRating">
                <key column="UserId" />
                <one-to-many class="UserRating"/>
            </bag>
        </class>
        <class name="Item" >
            <id name="ItemId" >
                <generator class="native" />
            </id>
            <property name="ItemName" />
            <bag name="Ratings" generic="true" inverse="true" table="UserRating">
                <key column="ItemId" />
                <one-to-many class="UserRating"/>
            </bag>
        </class>
        <class name="UserRating" >
            <composite-id>
                <key-many-to-one class="User" column="UserId" name="User" />
                <key-many-to-one class="Item" column="ItemId" name="Item" />
            </composite-id>
            <property name="Rating" />
        </class>
    </hibernate-mapping>
    

    I would suggest you look at the Summer of Nhibernate screen cast as well as the Autumn of Agile series by Stephen Bohlen which gave me a great start with nhibernate.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You code is almost done already, you just seem to… May 13, 2026 at 4:03 pm
  • Editorial Team
    Editorial Team added an answer They're the same. If you look at this code in… May 13, 2026 at 4:03 pm
  • Editorial Team
    Editorial Team added an answer This has been asked many times before Try Math.Round(val*20)/20 See… May 13, 2026 at 4:03 pm

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
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
I have a French site that I want to parse, but am running into
I have text I am displaying in SIlverlight that is coming from a CMS

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.