Castle.ActiveRecord.ActiveRecordBase.InternalSave C# (CSharp) Method

InternalSave() private static method

Saves 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 InternalSave ( object instance, bool flush ) : void
instance object The ActiveRecord instance to be saved
flush bool if set to true, the operation will be followed by a session flush.
return void
		private static void InternalSave(object instance, bool flush)
		{
			if (instance == null) throw new ArgumentNullException("instance");

			EnsureInitialized(instance.GetType());

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

			try
			{
				session.SaveOrUpdate(instance);

				if (flush)
				{
					session.Flush();
				}
			}
			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 Save for " + instance.GetType().Name, ex);
				}
			}
			finally
			{
				holder.ReleaseSession(session);
			}
		}