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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:24:57+00:00 2026-06-09T15:24:57+00:00

This is my AbstractNHibernateDao, i’d like to use SaveOrUpdateCopy with Merge command, but when

  • 0

This is my AbstractNHibernateDao, i’d like to use SaveOrUpdateCopy with Merge command, but when i’m trying to use with Type T I have following error

Error 1 The type ‘T’ must be a reference type in order to use it as
parameter ‘T’ in the generic type or method
‘NHibernate.ISession.Merge(T)’

public abstract class AbstractNHibernateDao<T, TIdT> : IDao<T, TIdT>
    {
        private readonly Type _persitentType = typeof (T);

        /// <summary>
        ///   Exposes the ISession used within the DAO.
        /// </summary>
        private static ISession NHibernateSession
        {
            get { return NHibernateSessionManager.Instance.GetSession(); }
        }

        #region IDao<T,TIdT> Members



        /// <summary>
        ///   For entities that have assigned ID's, you must explicitly call Save to add a new one. See http://www.hibernate.org/hib_docs/reference/en/html/mapping.html#mapping-declaration-id-assigned.
        /// </summary>
        public T Save(T entity)
        {
            NHibernateSession.Save(entity);
            NHibernateSession.Flush();
            return entity;
        }

        /// <summary>
        ///   For entities with automatatically generated IDs, such as identity, SaveOrUpdate may be called when saving a new entity. SaveOrUpdate can also be called to update any entity, even if its ID is assigned.
        /// </summary>
        public T SaveOrUpdate(T entity)
        {
            NHibernateSession.SaveOrUpdate(entity);
            NHibernateSession.Flush();
            return entity;
        }

        public T SaveOrUpdateCopy(T entity)
        {
            NHibernateSession.Merge(entity);
            return entity;
        } 

        public void Delete(T entity)
        {
            NHibernateSession.Delete(entity);
            NHibernateSession.Flush();
        }

        /// <summary>
        ///   Commits changes regardless of whether there's an open transaction or not
        /// </summary>
        public void CommitChanges()
        {
            if (NHibernateSessionManager.Instance.HasOpenTransaction())
            {
                NHibernateSessionManager.Instance.CommitTransaction();
            }
            else
            {
                // If there's no transaction, just flush the changes
                NHibernateSessionManager.Instance.GetSession().Flush();
            }
        }

    }

How could i use it?

  • 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-09T15:24:58+00:00Added an answer on June 9, 2026 at 3:24 pm

    You should do Merge(entity) instead of Merge(T):

    public abstract class AbstractNHibernateDao<T, TIdT> 
        : IDao<T, TIdT> where T : class
    {
        public T SaveOrUpdateCopy(T entity)
        {
            NHibernateSession.Merge(entity);
            return entity;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is in regards to merge XCode project.pbxproj files, but the same principle applies
this gives me an error, Bad Reciever type 'NSIntegar (aka 'int'). NSString *tempTag =
This might seem like a stupid question I admit. But I'm in a small
This is a normalization thing, but I want I have to hold information about
this is what i have so far: type u = {str : string} //some
This may be an unusual question, but are there any resources people have come
This silverlight code throws an error Cannot invoke a non-delegate type var WshShell =
this is my first question in here, and I would like to ask if
This should be a simple one: I have an observableArray object called To in
This code below allows me to find the word error in all my files

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.