Click here to Skip to main content
15,897,704 members
Articles / Database Development / SQL Server

Optimizing Performance in NHibernate: Part 2: A Collection of Enhancements

Rate me:
Please Sign up or sign in to vote.
4.86/5 (24 votes)
9 May 2007CPOL19 min read 199.6K   810   110  
This is the second part in a two-piece article focused on optimizing the efficiency of your NHibernate ORM layer.
using System;
using System.Collections.Generic;
using System.Text;

namespace Northwind.Domain.Entities.Errors
{
	/// <summary>
	/// Collection of Validation Failures built when an 
	/// object is validated.
	/// </summary>
	public class ValidationFailureCollection
		: List<ValidationFailure>
	{
		private bool _containsError;

		public ValidationFailureCollection() : base( )
		{
			_containsError = false;
		}

		/// <summary>
		/// Checks the IsError on the validaiton failure being
		/// added and sets _containsError appropiately.
		/// </summary>
		/// <param name="failure"></param>
		public new void Add( ValidationFailure failure )
		{
			base.Add(failure);
			if (failure.IsError)
				_containsError = true;
		}

		/// <summary>
		/// Hides the base class Clear to let us clear the
		/// _containsError flag.
		/// </summary>
		public new void Clear()
		{
			_containsError = false;
			base.Clear();
		}

		public void AddChildFailures(ValidationFailureCollection childCollection, string prefix)
		{
			foreach (ValidationFailure failure in childCollection)
			{
				failure.Prefix = prefix + ":" + failure.Prefix;

				//If the child collection contains an error, we now do too.
				if (failure.IsError)
					_containsError = true;
			}

			AddRange(childCollection);
		}

		/// <summary>
		/// Indicates if the collection contans at least one
		/// validation failure which is an error.
		/// </summary>
		public bool ContainsError
		{
			get { return _containsError; } 
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
United States United States
Independent contract developer for .NET data-oriented systems.

not much to say about myself but feel free to contact me for any inquiries and comments!

Comments and Discussions