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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:17:32+00:00 2026-06-15T10:17:32+00:00

So, I think it’s a bit odd to have a Save method which does

  • 0

So, I think it’s a bit odd to have a Save method which does not return the entity which has just been successfully saved. However, the entity passed into Save is modified by the function.

Example:

//T SaveOrUpdate(T entity); from IDao
PlaylistDao.SaveOrUpdate(playlist);

This function takes a playlist, saves it to the database, and returns the saved playlist. But, the paramater being passed into SaveOrUpdate is reference equals to its return value.

With this in mind, which is a more clear implementation:

public void SavePlaylist(Playlist playlist)
{
    try
    {
        NHibernateSessionManager.Instance.BeginTransaction();
        PlaylistDao.SaveOrUpdate(playlist);
        NHibernateSessionManager.Instance.CommitTransaction();
    }
    catch (Exception exception)
    {
        Logger.Error(exception);
        throw;
    }
}

vs

public Playlist SavePlaylist(Playlist playlist)
{
    Playlist savedPlayist;
    try
    {
        NHibernateSessionManager.Instance.BeginTransaction();
        savedPlayist = PlaylistDao.SaveOrUpdate(playlist);
        NHibernateSessionManager.Instance.CommitTransaction();
    }
    catch (Exception exception)
    {
        Logger.Error(exception);
        throw;
    }

    return savedPlayist;
}

I think that the second function is more clear to someone who has not seen the code before, but the first implementation is more succinct and more clear once the developer understands. Any thoughts?

UPDATE: To be clear, SaveOrUpdate has side-effects on playlist. When playlist is saved to the database, its ID field is updated with a value provided by the DB.

  • 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-06-15T10:17:34+00:00Added an answer on June 15, 2026 at 10:17 am

    I would go for the first method but with a small change–pass the argument with ref. (See the comments.) The problem I have with the second is that you are creating an extra variable unnecessarily. Why not just add some <summary> tags to the first method, indicating in intellisense what is going to happen to clarify any confusion? For me, this is better than creating an extra variable to essentially do the same thing.

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

Sidebar

Related Questions

Think of it as more of a collection of elements which are not necessarily
I think I have a fairly basic question here. I'm not trying to waste
I have an array which has BIG numbers and small numbers in it. I
Think I have an integer array like this: a[0]=60; a[1]=321; a[2]=5; now I want
I think I have a basic understanding of this, but am hoping that someone
I think this could be a very easy question for you. But I have
Think about the classic installation process, where you have a next button and when
Think google have a limitation for user , so users have to login to
Think you are the proud owner of Facebook, then which data you want to
Think 2 entities OneToOne mapped. Person and Car. A Person can have a Car.

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.