Castle.ActiveRecord.ActiveRecordBase.InternalSaveCopy C# (CSharp) Метод

InternalSaveCopy() приватный статический Метод

Saves a copy of the instance to the database. If the primary key is unitialized it creates the instance on the database. Otherwise it updates it.

If the primary key is assigned, then you must invoke Create() or Update() instead.

private static InternalSaveCopy ( object instance, bool flush ) : object
instance object The transient instance to be saved
flush bool if set to true, the operation will be followed by a session flush.
Результат object
        private static object InternalSaveCopy(object instance, bool flush)
        {
            if (instance == null) throw new ArgumentNullException("instance");

            EnsureInitialized(instance.GetType());

            ISession session = holder.CreateSession(instance.GetType());

            try
            {
                object persistent = session.SaveOrUpdateCopy(instance);

                if (flush)
                {
                    session.Flush();
                }

                return persistent;
            }
            catch (ValidationException)
            {
                holder.FailSession(session);

                throw;
            }
            catch (Exception ex)
            {
                holder.FailSession(session);

                // NHibernate catches our ValidationException on Create so it could be the innerexception here
                if (ex.InnerException is ValidationException)
                {
                    throw ex.InnerException;
                }
                else
                {
                    throw new ActiveRecordException("Could not perform SaveCopy for " + instance.GetType().Name, ex);
                }
            }
            finally
            {
                holder.ReleaseSession(session);
            }
        }