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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:52:53+00:00 2026-05-21T07:52:53+00:00

I have been confused about ORM since I see the following sample code: public

  • 0

I have been confused about ORM since I see the following sample code:

public class Article
{
    public List<Comment> Comments;

    public void AddComment(Comment comment)
    {
        Comments.Add(comment);
    }

    // I'm surprised by this kind of operation
    // how much performance hit it should be
    public void Save()
    { 
        //update the article and all its comments
    }
}

According to what I think, the responsiblity of saving comment should be assigned to the comment itself:

public class Comment
{
    public Article BelongArticle;

    //I think this is better/direct than use object Article,
    //But it's based on the consideration of database structure,
    //I was told one should "forget" the database, but it's really hard
    public int ArticleId;   

    public void Save()
    { 
        //save the comment directly
    }
}
  • 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-21T07:52:54+00:00Added an answer on May 21, 2026 at 7:52 am

    You are reaching conclusions without any real basis because you are just looking at some sample code and not considering what actually might be happening.

    The whole point of using an ORM is so you can allow it to handle the database transactions while you work in an object oriented rather than a relational fashion in your application. You really cannot say anything about how the ORM performs when you do an update on Article by just looking at Article.Save. Article.Save is an OO construct, and what the ORM actually executes on the database is a relational action. What about Article.Save makes you think it is inefficient? Looking at that does not give you any information. You would have to look at what the ORM of choice is doing on the database.

    Suppose the Article is a new object. In this case you have to save the Article, set the foreign key in the Comment, and then save the comment. Your “preferred” code does not show the full operation but it still must occur. The difference is the ORM gives you an object oriented way to do this – just call save on the article. Under the hood the same operations must occur either way. Maybe the ORM takes more steps than you could do it in manually, but maybe not.

    Suppose Article is not a new object. You add a new Comment. Depending on the platform, when you call Save this time potentially what happens with an ORM could be no different than what you might think as better depending on how your code is written. If there is nothing that needs to be updated in the Article, the ORM may simply save the Comment.

    ORMs use various methods, but in general they maintain some kind of running account of objects that need to be updated.

    You cannot just say that the first approach is somehow inefficient just on face because you called a method on Article instead of Comment – what is actually happening will depend on the specific ORM platform you use as well as the state of the objects.

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

Sidebar

Related Questions

I have been looking at this code and I'm confused about the rep cmpsb
I'm confused about this. Most of us have been told that there isn't any
I have always been kind of confused by threads, and my class right now
I have been reading about using Spring with Hibernate and I am really confused
I have been learning OpenGL and SDL lately and I've become rather confused about
I'm rails noob, and have been confused about sending params from controller to model.
We have been discussing this at work and now I am even more confused
So I am a little confused, I have been looking around trying to determine
Have been reading about async and tasks and been attempting to convert the CopyFileEx
I have been reading about bit operators in Objective-C in Kochan's book, Programming in

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.