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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:19:22+00:00 2026-05-16T01:19:22+00:00

This is something that has been pulling at me for a while. Consider a

  • 0

This is something that has been pulling at me for a while. Consider a (MVC type) web application with an ORM (e.g. Nhiberate) as the data access layer.

On one hand – the OOP/Rich domain model hand – I feel I should be passing around (references to) the real objects I am talking about.

On the other hand – the DB/Web App hand – I feel that it is easier and more efficient just to pass the integer Ids of the objects rather than the object themselves.

Consider an ecommerce catalogue type application:

  • The user is logged in and navigates to a product page.
  • They post a comment.
  • The controller action tasked with persisting this comment has 3 pieces of information: a) The user id (from the auth cookie or wherever), b) The product id (probably from the querystring), and c) the comment text.
  • Now, what what is best practice here? Is it really worth inflating the user and product objects (e.g. by getting them from the repository, with all the DB work that entails) when we know that all they will be used for is so the ORM can read their IDs and set the appropriate foreign keys in the DB table that stores the comments?

What are peoples views on this? Perhaps web apps should be given a little more leway than other apps, due to their stateless nature? I imagine there will be ‘it depends’ answers, but maybe some people are purists about the issue.

This is a general question which probably is applicable to many platforms, but if giving examples I would prefer them to be ASP.NET MVC if possible.

Thank you.

  • 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-16T01:19:23+00:00Added an answer on May 16, 2026 at 1:19 am

    NHibernate has the load operation (as opposed to doing a get) exactly for this reason.

    session.Save(
      new Comment
          {
             Text = commentTextFromScreen,
             User = session.Load<User>(userID),
             Product = session.Load<Product>(productID)
          }
    };
    

    In the above example, you are telling NHibernate: I know these already exist in the database, so don’t bother selecting them right now. NHibernate will return proxy objects for them and a select won’t happen against the database as long as you don’t attempt to access any properties on the objects.

    For more info check out Ayende’s blog post: The difference between Get, Load, and query by id.

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

Sidebar

Related Questions

This is something that's been bugging me with PHP for a while now and
I can see that this is something that has been troubling a lot of
This is something that has been driving me mad over the past few days.
I know this is something that has been discussed over and over, and I
This is something that's been bugging me for many years: why most online services
So this is something that I have not been able to find any documentation
I'm deploying something that has been running on my local and realized when I
Something that has been bugging me since I read an answer on another stackoverflow
I'm building a web-based productivity application that has to deal with modest user concurrency,
I apologize if this has been answered else where, I've been pulling my hair

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.