Click here to Skip to main content
15,886,362 members
Articles / Desktop Programming / Windows Forms

Three-tier .NET Application Utilizing Three ORM Technologies

Rate me:
Please Sign up or sign in to vote.
4.95/5 (118 votes)
30 Jan 2010CPOL109 min read 163.9K   4.4K   437  
LINQ to SQL, Entity Framework, and NHibernate used in a parallel fashion in a three-tier WinForms application.
using System;
using System.Collections.Generic;
using System.Text;
using s = System;
using System.Linq;
using gt=GlobalType;

namespace DomainUtil
{
	public class Participants
	{
		gt.IParticipant[] _arrParticipants;
		s.Collections.Generic.Dictionary<int, int> _dictOfIndexesByID;
		public Participants(IList<gt.IParticipant> lstParticipants)
		{
			IEnumerable<gt.IParticipant> sorted = lstParticipants.OrderBy(o=>o.ID);
			_arrParticipants = sorted.ToArray();
			_dictOfIndexesByID = new Dictionary<int,int>();
			int i = -1;
			foreach(gt.IParticipant aParticipant in sorted)
			{
				i++;
				_dictOfIndexesByID.Add(aParticipant.ID, i);
			}
		}
		public int IndexFromID(int iID)
		{
			return _dictOfIndexesByID[iID];
		}
		public string NameFromIndex(int iIndex)
		{
			return _arrParticipants[iIndex].Name;
		}
		public string NameFromID(int iID)
		{
			return NameFromIndex(IndexFromID(iID));
		}
		public int IDFromIndex(int iIndex)
		{
			return _arrParticipants[iIndex].ID;
		}

		public int Count
		{
			get
			{
				return _arrParticipants.Length;
			}
		}
		public int[] GetArrayOfIDs()
		{
			int[] arr = new int[_arrParticipants.Length];
			for (int i = 0; i < _arrParticipants.Length; i++)
			{
				arr[i] = _arrParticipants[i].ID;
			}
			return arr;
		}
		public gt.IParticipant[] GetArryOfObjects()
		{
			gt.IParticipant[] arr = new gt.IParticipant[_arrParticipants.Length];
			for (int i = 0; i < _arrParticipants.Length; i++)
			{
				arr[i] = _arrParticipants[i];
			}
			return arr;
		}
	}
}

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
Software Developer (Senior) Austin Regional Clinic
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions