Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Developing Next Generation Smart Clients using .NET 2.0 working with Existing .NET 1.1 SOA-based XML Web Services

, 16 Aug 2005
Comprehensive guide to development of .NET 2.0 Smart Clients working with existing Service Oriented Architecture based XML web services, fully utilizing the Enterprise Library
smartclientsoa_src.zip
SmartClient
Client
SMI.App
Controls
Forms
Modules
Properties
app.manifest
Settings.settings
Resources
240.png
Bottom.png
BuilderDialog_delete.bmp
DarkBlue.bmp
download-xp.gif
Earth.png
fldropen.png
iSync.gif
Leonardo_da_Vinci_My_Computer.png
LightBlue.bmp
LoginBox.jpg
LoginButton.jpg
LoginButton1.jpg
LoginButton2.jpg
Logo1.png
LogoPic.jpg
Middle.png
Refresh.bmp
refresh.ico
refresh1.ico
RightArrow.bmp
SuccessComplete.bmp
Task.bmp
Tasks.png
Top.png
TurnOffButton.bmp
wi0062-32.ico
wi0063-32.ico
wi0064-16.ico
wi0064-32.ico
SmartInstitute.App.csproj.user
wi0064-32.ico
SMI.Automation
Commands
Course
Framework
Security
Students
UI
Controls
Documents
MiscDocuments
StudentDocuments
Factories
Forms
Helpers
Misc
Properties
Settings.settings
Resources
BuilderDialog_delete.bmp
LogoSmall.bmp
Misho.jpg
My Pic 7.jpg
table.ico
SmartInstitute.Automation.csproj.user
Web References
SmartInstituteServices.AccountService
Account.datasource
AccountService.disco
AccountService.wsdl
Reference.map
SmartInstituteServices.CourseService
Course.datasource
CourseService.disco
CourseService.wsdl
Reference.map
SmartInstituteServices.SecurityService
Reference.map
SecurityService.disco
SecurityService.wsdl
SmartInstituteServices.StudentService
Reference.map
Student.datasource
StudentService.disco
StudentService.wsdl
SMI.ObjectModel.Enhanced
Base
Models
Properties
Settings.settings
Settings
SmartInstitute.ObjectModel.csproj.user
UMS.ObjectModel.Enhanced.csproj.user
SMI.Objects
SmartInstitute.csproj.user
CodeSmith
Tier
BusinessLogicLayer
Entity.cst
EntityBase.cst
EntityCollection.cst
EntityCollectionBase.cst
Enum.cst
IEntity.cst
DataAccessLayer
App.config.cst
CommonSql.cst
Configuration.cst
DBConcurrencyException.cst
DBException.cst
Factories
EntityRepositoryFactory.cst
IEntityRepository.cst
SqlClient
CVS
Entries
Entries.Extra
Entries.Extra.Old
Entries.Old
Repository
Root
TortoiseCVS.Status
SqlEntityRepository.cst
SqlEntityRepositoryBase.cst
TransactionManager.cst
UnitTests
EntityRepositoryTest.cst
WebServiceClient
WsEntityRepository.cst
WsEntityRepositoryBase.cst
Main.cst
nant.cst
References
GotDotNet.ApplicationBlocks.Data.dll
Microsoft.ApplicationBlocks.Data.dll
nunit.framework.dll
StoredProcedures.cst
vsnet2003.project.cst
vsnet2003.solution.cst
vsnet2005.project.cst
vsnet2005.solution.cst
WebService
Web.config.cst
WebService.cst
Database
SmartInstitute.bak
Library
Microsoft.Practices.EnterpriseLibrary.Caching.dll
Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Configuration.dll
Microsoft.Practices.EnterpriseLibrary.Data.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.dll
Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Logging.dll
Microsoft.Practices.EnterpriseLibrary.Logging.dll
Microsoft.Practices.EnterpriseLibrary.Security.ActiveDirectory.dll
Microsoft.Practices.EnterpriseLibrary.Security.Cache.CachingStore.dll
Microsoft.Practices.EnterpriseLibrary.Security.Cryptography.dll
Microsoft.Practices.EnterpriseLibrary.Security.Database.Authentication.dll
Microsoft.Practices.EnterpriseLibrary.Security.Database.dll
Microsoft.Practices.EnterpriseLibrary.Security.dll
nunit.core.dll
nunit.framework.dll
Server
BLL
SmartInstitute.csproj.user
DAL
Factories
SmartInstitute.DataAccessLayer.csproj.user
SqlClient
Utilities
GotDotNet.ApplicationBlocks.Data.dll
Microsoft.ApplicationBlocks.Data.dll
nunit.framework.dll
UnitTests
SmartInstitute.build
SmartInstitute.Facade
FacadeTest
SmartInstitute.Facade.csproj.user
SmartInstitute.Test
App.ico
SmartInstitute.Test.csproj.user
SmartInstituteServices
Global.asax
log
SmartInstituteServices.csproj.webinfo
SQL
Setup
SecurityDatabase
SecurityDatabaseConsole
App.ico
SecurityDatabaseConsole.exe.manifest
SR.strings
Tests
Tools.SecurityDatabaseConsole.csproj.user
	 
#region "Using directives"

using System;
using System.Data;
using System.Data.SqlClient;
//using Microsoft.ApplicationBlocks.Data;
using System.Collections;
using System.Diagnostics;
using SmartInstitute;

#endregion

namespace SmartInstitute.DataAccessLayer.SqlClient
{

/// <summary>
///	This class is the base repository for the CRUD operations on the CourseSection objects.
/// </summary>
public class CourseSectionRepositoryBase : ICourseSectionRepository
{
	#region "Declarations"	
	
	/// <summary>
	/// Connection String.
	/// </summary>
	protected string connectionString = string.Empty;
	
	
	/// <summary>
	/// <see cref="TransactionManager"/> object.
	/// </summary>
	protected TransactionManager transactionManager;
	
	private static volatile CourseSectionRepositoryBase current;
   	private static object syncRoot = new Object();
	
	#endregion "Declarations"
	
	
	#region "Constructors"
		
	/// <summary>
	/// Creates a new <see cref="CourseSectionRepositoryBase"/> instance.
	/// Uses connection string to connect to datasource.
	/// </summary>
	/// <param name="connectionString">Connection string.</param>
	protected CourseSectionRepositoryBase(string connectionString)
	{
		this.connectionString = connectionString;
	}
	
	/// <summary>
	///	Creates a new <see cref="CourseSectionRepositoryBase"/> instance.
	/// Uses connection string to connect to datasource.
	/// If a transaction is open, it will use the transaction, otherwise it will use the connection string from the transaction manager object.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object.</param>
	protected CourseSectionRepositoryBase(TransactionManager transactionManager)
	{
		this.transactionManager = transactionManager;
		this.connectionString = this.transactionManager.ConnectionString;
	}
	
	#endregion "Constructors"
	
	#region Public properties
	
	///<summary>
	/// The current CourseSectionRepositoryBase instance.
	///</summary>
	///<value></value>
	public static CourseSectionRepositoryBase Current
	{
	  get 
	  {
	     if (current == null) 
	     {
	        lock (syncRoot) 
	        {
	           if (current == null)
	           {
			   		current = new CourseSectionRepositoryBase(string.Empty);
			   }
	        }
	     }
	     return current;
	  }
	}
	
	///<summary>
	/// Gets or sets the connectionstring to the database.
	///</summary>
	///<value></value>
	public string ConnectionString
	{
		get {return this.connectionString;}
		set {this.connectionString = value;}
	}
	
	
	///<summary>
	/// Gets or sets the TransactionManager instance.
	///</summary>
	///<value></value>
	public TransactionManager TransactionManager
	{
		get {return this.transactionManager;}
		set {this.transactionManager = value;}
	}
	
	#endregion
	
	#region "Get from  Many To Many Relationship Functions"
	#endregion
	
	#region "Delete Functions"
	
	/// <summary>
	/// 	Deletes a row from the DataSource.
	/// </summary>
	/// <param name="ID">. Primary Key.</param>	
    /// <param name="ChangeStamp">Concurrency Parameter. </param>
	/// <returns>Returns true if operation suceeded.</returns>
	public bool Delete(System.Int32 ID, DateTime ChangeStamp)
	{
		if(UseTransaction())
		{
			return Delete(this.transactionManager, ID, ChangeStamp);
		}
		else
		{
			return Delete(this.connectionString, ID, ChangeStamp);
		}
	}//end Delete
	
	/// <summary>
	/// 	Deletes a row from the DataSource.
	/// </summary>
	/// <param name="entity">CourseSection object containing data.</param>
	/// <remarks>Deletes based on primary key(s).</remarks>
	/// <returns>Returns true if operation suceeded.</returns>
	public bool Delete(CourseSection entity)
	{
		if(UseTransaction())
		{
			return Delete(this.transactionManager, entity.ID, entity.ChangeStamp);	
		}
		else
		{
			return Delete(this.connectionString, entity.ID, entity.ChangeStamp);	
		}
	}//end Delete
	/// <summary>
	/// 	Deletes rows from the DataSource.
	/// </summary>
	/// <param name="entityCollection">CourseSectionCollection containing data.</param>
	/// <remarks>Deletes CourseSections only when IsDeleted equals true.</remarks>
	/// <returns>Returns the number of successful delete.</returns>
	public int Delete(CourseSectionCollection entityCollection)
	{
		if(UseTransaction())
			return Delete(this.transactionManager, entityCollection);
		else
			return Delete(this.connectionString, entityCollection);
	}
	
	
	/// <summary>
	/// 	Deletes a rows from the DataSource.
	/// </summary>
	/// <param name="entityCollection">CourseSectionCollection containing data.</param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks>Deletes CourseSections only when IsDeleted equals true.</remarks>
	/// <returns>Returns the number of successful delete.</returns>
	public int Delete(string connectionString, CourseSectionCollection entityCollection)
	{
		int number = 0;
		foreach (CourseSection entity in entityCollection)
		{
			if ( Delete(connectionString, entity) )
			{
				number++;
			}
		}
		return number;
	}
	
	/// <summary>
	/// 	Deletes a rows from the DataSource.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="entityCollection">CourseSectionCollection containing data.</param>
	/// <remarks>Deletes CourseSections only when IsDeleted equals true.</remarks>
	/// <returns>Returns the number of successful delete.</returns>
	public int Delete(TransactionManager transactionManager, CourseSectionCollection entityCollection)
	{
		int number = 0;
		foreach (CourseSection entity in entityCollection)
		{
			if ( Delete(transactionManager, entity) )
			{
				number++;
			}
		}
		return number;
	}
	
	
	/// <summary>
	/// 	Deletes a row from the DataSource.
	/// </summary>
	/// <param name="entity">CourseSection object containing data.</param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks>Deletes based on primary key(s).</remarks>
	/// <returns>Returns true if operation suceeded.</returns>
	public bool Delete(string connectionString, CourseSection entity)
	{
		return Delete(null, connectionString,entity.ID, entity.ChangeStamp);	
	}
	
	
	/// <summary>
	/// 	Deletes a row from the DataSource.
	/// </summary>
	/// <param name="ID">. Primary Key.</param>	
	/// <param name="connectionString">Connection string to datasource.</param>
    /// <param name="ChangeStamp">Concurrency Parameter. </param>
	/// <remarks>Deletes based on primary key(s).</remarks>
	/// <returns>Returns true if operation suceeded.</returns>
	public bool Delete(string connectionString, System.Int32 ID, DateTime ChangeStamp)
	{
		return Delete(null, connectionString,ID, ChangeStamp);
	}
	
	
	/// <summary>
	/// 	Deletes a row from the DataSource.
	/// </summary>
	/// <param name="entity">CourseSection object containing data.</param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <remarks>Deletes based on primary key(s).</remarks>
	/// <returns>Returns true if operation suceeded.</returns>
	public bool Delete(TransactionManager transactionManager, CourseSection entity)
	{
		if (transactionManager.IsOpen)
			return Delete(transactionManager, null, entity.ID, entity.ChangeStamp);	
		else
			return Delete(null, transactionManager.ConnectionString, entity.ID, entity.ChangeStamp);	
	}
	
	
	/// <summary>
	/// 	Deletes a row from the DataSource.
	/// </summary>
	/// <param name="ID">. Primary Key.</param>	
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
    /// <param name="ChangeStamp">Concurrency Parameter. </param>
	/// <remarks>Deletes based on primary key(s).</remarks>
	/// <returns>Returns true if operation suceeded.</returns>
	public bool Delete(TransactionManager transactionManager, System.Int32 ID, DateTime ChangeStamp)
	{
		if (transactionManager.IsOpen)
			return Delete(transactionManager, null, ID, ChangeStamp);
		else
			return Delete(null, transactionManager.ConnectionString, ID, ChangeStamp);
	}
	
	
	
	/// <summary>
	/// 	Deletes a row from the DataSource.
	/// </summary>
	/// <param name="ID">. Primary Key.</param>	
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks>Deletes based on primary key(s).</remarks>
	/// <returns>Returns true if operation suceeded.</returns>
	protected bool Delete(TransactionManager transactionManager, string connectionString, System.Int32 ID, DateTime ChangeStamp)
	{
		int result = 0;
		if (transactionManager != null)
			result = SqlHelper.ExecuteNonQuery(transactionManager.TransactionObject, "prc_CourseSection_Delete", ID, ChangeStamp);
		else
			result = SqlHelper.ExecuteNonQuery(connectionString, "prc_CourseSection_Delete", ID, ChangeStamp);
			
		Debug.WriteLine("CourseSectionRepository.Delete Affected " + result + " records.");
		if (result == 0) {
			ThrowDeleteConcurrencyException( ID, ChangeStamp);
		} 
		return Convert.ToBoolean(result);
	}//end Delete
	
	
	/// <summary>
	/// Throws the delete concurrency exception.
	/// </summary>
	/// <param name="ID">. Primary Key.</param>	
	protected void ThrowDeleteConcurrencyException(System.Int32 ID, DateTime ChangeStamp)
	{
		DBConcurrencyException conflict = new DBConcurrencyException("Concurrency exception: Cannot delete entity as it does not exist.");
		//conflict.ModifiedRecord = entity;
		throw conflict;
	}
	
	
	#endregion

		
	#region "GetList Functions"
	
	
	/// <summary>
	/// 	Gets All rows from the DataSource.
	/// </summary>
	/// <remarks>Uses connection string object was created with.</remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetAll()
	{	
		if(UseTransaction())
		{
			return GetAll(this.transactionManager);
		}
		else
		{
			return GetAll(this.connectionString);
		}
	}
	
	/// <summary>
	/// 	Gets All rows from the DataSource.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <remarks>Uses connection string object was created with.</remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetAll(int start, int pagelen)
	{	
		if(UseTransaction())
		{
			return GetAll(this.transactionManager, start, pagelen);
		}
		else
		{
			return GetAll(this.connectionString, start, pagelen);
		}
	}
	
	
	/// <summary>
	/// 	Gets All rows from the DataSource.
	/// </summary>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetAll(string connectionString)
	{
		return GetAll(null, connectionString,0,int.MaxValue);
	}
	
	/// <summary>
	/// 	Gets All rows from the DataSource.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetAll(string connectionString, int start, int pagelen)
	{
		return GetAll(null, connectionString, start, pagelen);
	}//end getall
	
	
	/// <summary>
	/// 	Gets All rows from the DataSource.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetAll(TransactionManager transactionManager)
	{
		if (transactionManager.IsOpen)
			return GetAll(transactionManager, null, 0,int.MaxValue);
		else
			return GetAll(null, transactionManager.ConnectionString, 0,int.MaxValue);
	}
	
	
	/// <summary>
	/// 	Gets All rows from the DataSource.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetAll(TransactionManager transactionManager, int start, int pagelen)
	{
		if (transactionManager.IsOpen)
			return GetAll(transactionManager, null, start, pagelen);
		else
			return GetAll(null, transactionManager.ConnectionString, start, pagelen);
	}//end getall
	
	/// <summary>
	/// 	Gets All rows from the DataSource.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	protected CourseSectionCollection GetAll(TransactionManager transactionManager, string connectionString, int start, int pagelen)
	{
		//Declare Varibles
		SqlDataReader reader;
		if (transactionManager != null)
			reader = SqlHelper.ExecuteReader(transactionManager.TransactionObject, "prc_CourseSection_Get_List");
		else
			reader = SqlHelper.ExecuteReader(connectionString, "prc_CourseSection_Get_List");
		//Create Collection
		CourseSectionCollection rows = new CourseSectionCollection();
		Fill(reader, rows, start, pagelen);
		reader.Close();
		return rows;
	}//end getall
	
	#endregion
	
	#region Paged Recordset
			
	/// <summary>
	/// Gets a page of rows from the DataSource.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="count">Number of rows in the DataSource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetPaged(int start, int pagelen, out int count)
	{
		if(UseTransaction())
		{
			return GetPaged(this.transactionManager, start, pagelen, out count);
		}
		else
		{
			return GetPaged(this.connectionString, start, pagelen, out count);
		}
	}
	
	/// <summary>
	/// Gets a page of rows from the DataSource.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="count">Number of rows in the DataSource.</param>
	/// <param name="whereClause">Specifies the condition for the rows returned by a query (Name='John Doe', Name='John Doe' AND Id='1', Name='John Doe' OR Id='1').</param>
	/// <param name="orderBy">Specifies the sort criteria for the rows in the DataSource (Name ASC; BirthDay DESC, Name ASC);</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetPaged(string whereClause, string orderBy, int start, int pagelen, out int count)
	{
		if(UseTransaction())
		{
			return GetPaged(this.transactionManager, whereClause, orderBy, start, pagelen, out count);
		}
		else
		{
			return GetPaged(this.connectionString, whereClause, orderBy, start, pagelen, out count);
		}
	}
	
	/// <summary>
	/// Gets a page of rows from the DataSource.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="count">Number of rows in the DataSource.</param>
	/// <param name="connectionString">The connection string to the datasource</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetPaged(string connectionString, int start, int pagelen, out int count)
	{
		return GetPaged(null, connectionString, null, null, start, pagelen, out count);
	}

	/// <summary>
	/// Gets a page of rows from the DataSource.
	/// </summary>
	/// <param name="whereClause">Specifies the condition for the rows returned by a query (Name='John Doe', Name='John Doe' AND Id='1', Name='John Doe' OR Id='1').</param>
	/// <param name="orderBy">Specifies the sort criteria for the rows in the DataSource (Name ASC; BirthDay DESC, Name ASC);</param>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="count">Number of rows in the DataSource.</param>
	/// <param name="connectionString">The connection string to the datasource</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetPaged(string connectionString, string whereClause, string orderBy, int start, int pagelen, out int count)
	{
		return GetPaged(null, connectionString, whereClause, orderBy, start, pagelen, out count);
	}
	
	/// <summary>
	/// Gets a page of rows from the DataSource.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="count">Number of rows in the DataSource.</param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetPaged(TransactionManager transactionManager, int start, int pagelen, out int count)
	{
		if (transactionManager.IsOpen)
			return GetPaged(transactionManager, null, null, null, start, pagelen, out count);
		else
			return GetPaged(null, transactionManager.ConnectionString, null, null, start, pagelen, out count);
	}
	
		/// <summary>
	/// Gets a page of rows from the DataSource.
	/// </summary>
	/// <param name="whereClause">Specifies the condition for the rows returned by a query (Name='John Doe', Name='John Doe' AND Id='1', Name='John Doe' OR Id='1').</param>
	/// <param name="orderBy">Specifies the sort criteria for the rows in the DataSource (Name ASC; BirthDay DESC, Name ASC);</param>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="count">Number of rows in the DataSource.</param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetPaged(TransactionManager transactionManager, string whereClause, string orderBy, int start, int pagelen, out int count)
	{
		if (transactionManager.IsOpen)
			return GetPaged(transactionManager, null, whereClause, orderBy, start, pagelen, out count);
		else
			return GetPaged(null, transactionManager.ConnectionString, whereClause, orderBy, start, pagelen, out count);
	}
	
	/// <summary>
	/// Gets a page of rows from the DataSource.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="count">Number of rows in the DataSource.</param>
	/// <param name="whereClause">Specifies the condition for the rows returned by a query (Name='John Doe', Name='John Doe' AND Id='1', Name='John Doe' OR Id='1').</param>
	/// <param name="orderBy">Specifies the sort criteria for the rows in the DataSource (Name ASC; BirthDay DESC, Name ASC);</param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	protected CourseSectionCollection GetPaged(TransactionManager transactionManager, string connectionString, string whereClause, string orderBy, int start, int pagelen, out int count)
	{
		
		//Declare Varibles
		SqlDataReader reader;
		if (transactionManager != null)
			reader = SqlHelper.ExecuteReader(transactionManager.TransactionObject, "prc_CourseSection_GetPaged", whereClause, orderBy, start, pagelen);
		else
			reader = SqlHelper.ExecuteReader(connectionString, "prc_CourseSection_GetPaged", whereClause, orderBy, start, pagelen);
		
		reader.Read();
		count = reader.GetInt32(0);
		reader.NextResult();

		//Create Collection
		CourseSectionCollection rows = new CourseSectionCollection();
		Fill(reader, rows, 0, int.MaxValue);
		reader.Close();
		return rows;
	}
	
	#endregion
	
	#region "Get By Foreign Key Functions"
	
	/// <summary>
	/// 	Gets rows from the datasource based on the FK_CourseSection_Course key.
	///		FK_CourseSection_Course Description: 
	/// </summary>
	/// <param name="CourseID"></param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetByCourseID(System.Int32 CourseID)
	{
		if(UseTransaction())
		{
			return GetByCourseID(this.transactionManager, CourseID, 0, int.MaxValue);;
		}
		else
		{
			return GetByCourseID(this.connectionString, CourseID, 0, int.MaxValue);
		}
	}
	
	/// <summary>
	/// 	Gets rows from the datasource based on the FK_CourseSection_Course key.
	///		FK_CourseSection_Course Description: 
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="CourseID"></param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetByCourseID(System.Int32 CourseID, int start, int pagelen)
	{
		if(UseTransaction())
		{
			return GetByCourseID(this.transactionManager, CourseID, start, pagelen);
		}
		else
		{
			return GetByCourseID(this.connectionString, CourseID, start, pagelen);
		}	
	}

	/// <summary>
	/// 	Gets rows from the datasource based on the FK_CourseSection_Course key.
	///		FK_CourseSection_Course Description: 
	/// </summary>
	/// <param name="CourseID"></param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetByCourseID(string connectionString, System.Int32 CourseID)
	{
		return GetByCourseID(null, connectionString, CourseID, 0,int.MaxValue);
	}
	
	
	/// <summary>
	/// 	Gets rows from the datasource based on the FK_CourseSection_Course key.
	///		FK_CourseSection_Course Description: 
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="CourseID"></param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetByCourseID(string connectionString, System.Int32 CourseID, int start, int pagelen)
	{
		return GetByCourseID(null, connectionString, CourseID, start, pagelen);
	}
	
	
	/// <summary>
	/// 	Gets rows from the datasource based on the FK_CourseSection_Course key.
	///		FK_CourseSection_Course Description: 
	/// </summary>
	/// <param name="CourseID"></param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetByCourseID(TransactionManager transactionManager, System.Int32 CourseID)
	{
		if (transactionManager.IsOpen)
			return GetByCourseID(transactionManager, null, CourseID, 0,int.MaxValue);
		else
			return GetByCourseID(null, transactionManager.ConnectionString, CourseID, 0,int.MaxValue);
	}
	
	/// <summary>
	/// 	Gets rows from the datasource based on the FK_CourseSection_Course key.
	///		FK_CourseSection_Course Description: 
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="CourseID"></param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetByCourseID(TransactionManager transactionManager, System.Int32 CourseID, int start, int pagelen)
	{
		if (transactionManager.IsOpen)
			return GetByCourseID(transactionManager, null, CourseID, start, pagelen);
		else
			return GetByCourseID(null, transactionManager.ConnectionString, CourseID, start, pagelen);
	}
	
	/// <summary>
	/// 	Gets rows from the datasource based on the FK_CourseSection_Course key.
	///		FK_CourseSection_Course Description: 
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="CourseID"></param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	protected CourseSectionCollection GetByCourseID(TransactionManager transactionManager, string connectionString, System.Int32 CourseID, int start, int pagelen)
	{
		//Declare varibles
		SqlDataReader reader;
		if (transactionManager != null)
			reader = SqlHelper.ExecuteReader(transactionManager.TransactionObject, "prc_CourseSection_GetByCourseID", CourseID);
		else
			reader = SqlHelper.ExecuteReader(connectionString, "prc_CourseSection_GetByCourseID", CourseID);
		//Create Collection
		CourseSectionCollection rows = new CourseSectionCollection();
		Fill(reader, rows, start, pagelen);
		reader.Close();
		return rows;
	}
	
	#endregion
	
	#region "Get By Index Functions"

	
	/// <summary>
	/// 	Gets rows from the datasource based on the PK_Section index.
	/// </summary>
	/// <param name="ID"></param>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetByID(System.Int32 ID)
	{
		if(UseTransaction())
		{
			return GetByID(this.transactionManager, ID, 0, int.MaxValue);
		}
		else
		{
			return GetByID(this.connectionString, ID, 0, int.MaxValue);
		}
	}
	
	
	/// <summary>
	/// 	Gets rows from the datasource based on the PK_Section index.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="ID"></param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetByID(System.Int32 ID, int start, int pagelen)
	{
		if(UseTransaction())
		{
			return GetByID(this.transactionManager, ID, start, pagelen);
		}
		else
		{
			return GetByID(this.connectionString, ID, start, pagelen);
		}
	}

	
	/// <summary>
	/// 	Gets rows from the datasource based on the PK_Section index.
	/// </summary>
	/// <param name="ID"></param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetByID(string connectionString, System.Int32 ID)
	{
		return GetByID(null, connectionString, ID, 0, int.MaxValue);
	}
	
	
	/// <summary>
	/// 	Gets rows from the datasource based on the PK_Section index.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="ID"></param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetByID(string connectionString, System.Int32 ID, int start, int pagelen)
	{
		return GetByID(null, connectionString, ID, start, pagelen);
	}

	
	/// <summary>
	/// 	Gets rows from the datasource based on the PK_Section index.
	/// </summary>
	/// <param name="ID"></param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetByID(TransactionManager transactionManager, System.Int32 ID)
	{
		if (transactionManager.IsOpen)
			return GetByID(transactionManager, null, ID, 0, int.MaxValue);
		else
			return GetByID(null, transactionManager.ConnectionString, ID, 0, int.MaxValue);
	}
	
	
	/// <summary>
	/// 	Gets rows from the datasource based on the PK_Section index.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="ID"></param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	public CourseSectionCollection GetByID(TransactionManager transactionManager, System.Int32 ID, int start, int pagelen)
	{
		if (transactionManager.IsOpen)
			return GetByID(transactionManager, null, ID, start, pagelen);
		else
			return GetByID(null, transactionManager.ConnectionString, ID, start, pagelen);
	}
	
	
	/// <summary>
	/// 	Gets rows from the datasource based on the PK_Section index.
	/// </summary>
	/// <param name="start">Row number at which to start reading.</param>
	/// <param name="pagelen">Number of rows to return.</param>
	/// <param name="ID"></param>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <remarks></remarks>
	/// <returns>Returns a typed collection of CourseSection objects.</returns>
	protected CourseSectionCollection GetByID(TransactionManager transactionManager, string connectionString, System.Int32 ID, int start, int pagelen)
	{
		//Declare Varibles
		SqlDataReader reader;
		if (transactionManager != null)
			reader = SqlHelper.ExecuteReader(transactionManager.TransactionObject, "prc_CourseSection_GetByID", ID);
		else
			reader = SqlHelper.ExecuteReader(connectionString, "prc_CourseSection_GetByID", ID);
		//Create collection and fill
		CourseSectionCollection rows = new CourseSectionCollection();
		Fill(reader, rows, start, pagelen);
		reader.Close();
		return rows;
	}
	

	#endregion "Get By Index Functions"

	#region "Insert Functions"

	/// <summary>
	/// 	Inserts a CourseSection object into the datasource.
	/// </summary>
	/// <param name="entity">CourseSection object to insert.</param>
	/// <remarks>After inserting into the datasource, the CourseSection object will be updated
	/// to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public bool Insert(CourseSection entity)
	{
		if(UseTransaction())
		{
			return Insert(this.transactionManager, entity);
		}
		else
		{
			return Insert(this.connectionString, entity);
		}
	}
	
	/// <summary>
	/// 	Insert rows in the datasource.
	/// </summary>
	/// <param name="entityCollection"><c>CourseSection</c> objects in a <c>CourseSectionCollection</c> object to insert.</param>
	/// <remarks>
	///		This function will only insert entity objects marked as dirty
	///		and have an identity field equal to zero.
	///		Upon inserting the objects, each dirty object will have the public
	///		method <c>Object.AcceptChanges()</c> called to make it clean.
	/// 	After inserting into the datasource, the <c>CourseSection</c> objects will be updated
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns the number of successful insert.</returns>
	public int Insert(CourseSectionCollection entityCollection)
	{
			if(UseTransaction())
		{
			return Insert(this.transactionManager, entityCollection);
		}
		else
		{
			return Insert(this.connectionString, entityCollection);
		}		
	}

		
	/// <summary>
	/// 	Insert rows in the datasource.
	/// </summary>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <param name="entityCollection"><c>CourseSection</c> objects in a <c>CourseSectionCollection</c> object to insert.</param>
	/// <remarks>
	///		This function will only insert entity objects marked as dirty
	///		and have an identity field equal to zero.
	///		Upon inserting the objects, each dirty object will have the public
	///		method <c>Object.AcceptChanges()</c> called to make it clean.
	/// 	After inserting into the datasource, the <c>CourseSection</c> objects will be updated
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns the number of successful insert.</returns>
	public int Insert(string connectionString, CourseSectionCollection entityCollection)
	{
		int number = 0;
		foreach (CourseSection entity in entityCollection)
		{
			if (entity.IsNew)
			{
				if (Insert(connectionString, entity) )
				{
					number++;
				}
			}
		}
		return number;
	}
	
	/// <summary>
	/// 	Insert rows in the datasource.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="entityCollection"><c>CourseSection</c> objects in a <c>CourseSectionCollection</c> object to insert.</param>
	/// <remarks>
	///		This function will only insert entity objects marked as dirty
	///		and have an identity field equal to zero.
	///		Upon inserting the objects, each dirty object will have the public
	///		method <c>Object.AcceptChanges()</c> called to make it clean.
	/// 	After inserting into the datasource, the <c>CourseSection</c> objects will be updated
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns the number of successful insert.</returns>
	public int Insert(TransactionManager transactionManager, CourseSectionCollection entityCollection)
	{
		int number = 0;
		foreach (CourseSection entity in entityCollection)
		{
			if (entity.IsNew)
			{
				if (Insert(transactionManager, entity) )
				{
					number++;
				}
			}
		}
		return number;
	}
	
	/// <summary>
	/// 	Inserts a CourseSection object into the datasource.
	/// </summary>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <param name="entity">CourseSection object to insert.</param>
	/// <remarks>After inserting into the datasource, the CourseSection object will be updated
	/// to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public bool Insert(string connectionString, CourseSection entity)
	{
		return Insert(null, connectionString, entity);
	}
	
	
	/// <summary>
	/// 	Inserts a CourseSection object into the datasource using a transaction.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="entity">CourseSection object to insert.</param>
	/// <remarks>After inserting into the datasource, the CourseSection object will be updated
	/// to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public bool Insert(TransactionManager transactionManager,  CourseSection entity)
	{
		if (transactionManager.IsOpen)
			return Insert(transactionManager, null, entity);
		else
			return Insert(null, transactionManager.ConnectionString, entity);
	}
	
	
	/// <summary>
	/// 	Inserts a CourseSection object into the datasource using a transaction.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <param name="entity">CourseSection object to insert.</param>
	/// <remarks>After inserting into the datasource, the CourseSection object will be updated
	/// to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	protected bool Insert(TransactionManager transactionManager, string connectionString, CourseSection entity)
	{
		//Declare variables			
		//IDataParameterCollection parameters;
		SqlDataReader reader;
		int result = 0;
		//Get Parameters
		//if (transactionManager != null)
		//	parameters = SqlHelperParameterCache.GetSpParameterSet(transactionManager.ConnectionString, "prc_CourseSection_Insert");
		//else
		//	parameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, "prc_CourseSection_Insert");
		//Assign values to parameters
		//AssignInsertParameters(parameters, entity);
		
		
		if (transactionManager != null)
			reader = SqlHelper.ExecuteReader(transactionManager.TransactionObject, "prc_CourseSection_Insert", 
			entity.Capacity,entity.ChangeStamp,entity.ClassID,entity.CourseID,entity.Description,entity.Status,entity.Title,entity.Type);
		else
			reader = SqlHelper.ExecuteReader(connectionString, "prc_CourseSection_Insert", 
			entity.Capacity,entity.ChangeStamp,entity.ClassID,entity.CourseID,entity.Description,entity.Status,entity.Title,entity.Type );
			
		Debug.WriteLine("CourseSectionRepository-Insert Affected " + reader.RecordsAffected + " records.");
		if (reader.RecordsAffected > 0)
		{
			//RefreshEntity closes the connection
			RefreshEntity(reader, entity);
			result = 1;
		}
		else
		{
			//must always close the connection
			reader.Close();
		}
		return Convert.ToBoolean(result);
	}
	
	
	
	
	/// <summary>
	/// Assigns the insert parameters from the CourseSection instance to the SqlParameter array.
	/// </summary>
	/// <param name="parameters">The <see cref="SqlParameter"/> array to fill.</param>
	/// <param name="entity">The <see cref="CourseSection"/> instance to read from.</param>
	/* protected void AssignInsertParameters(IDataParameterCollection paramCollection, CourseSection entity)
	{
		SqlParameter[] parameters = new SqlParameter[ paramCollection.Count ];
		paramCollection.CopyTo( parameters, 0 );
		
					parameters[0].Value = entity.Capacity;
					parameters[1].Value = entity.ChangeStamp;
					parameters[2].Value = entity.ClassID;
					parameters[3].Value = entity.CourseID;
					parameters[4].Value = entity.Description;
					parameters[5].Value = entity.Status;
					parameters[6].Value = entity.Title;
					parameters[7].Value = entity.Type;
	} */
	
	#endregion

	#region "Update Functions"
	
	
	/// <summary>
	/// 	Update an existing row in the datasource.
	/// </summary>
	/// <param name="entity">The <see cref="CourseSection"/> instance to update.</param>
	/// <remarks>After updating the datasource, the CourseSection object will be updated
	/// to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public bool Update(CourseSection entity)
	{
		if(UseTransaction())
		{
			return Update(this.transactionManager, entity);
		}
		else
		{
			return Update(this.connectionString, entity);
		}		
	}		
	
	/// <summary>
	/// 	Update existing rows in the datasource.
	/// </summary>
	/// <param name="entityCollection"><c>CourseSection</c> objects in a <c>CourseSectionCollection</c> object to update.</param>
	/// <remarks>
	///		This function will only update entity objects marked as dirty
	///		and do not have an primary key value of 0.
	///		Upon updating the objects, each dirty object will have the public
	///		method <c>Object.AcceptChanges()</c> called to make it clean.
	/// 	After updating the datasource, the <c>CourseSection</c> objects will be updated
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns the number of successful update .</returns>
	public int Update(CourseSectionCollection entityCollection)
	{
		if(UseTransaction())
		{
			return Update(this.transactionManager, entityCollection);
		}
		else
		{
			return Update(this.connectionString, entityCollection);
		}	
	}

	
	/// <summary>
	/// 	Update existing rows in the datasource.
	/// </summary>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <param name="entityCollection"><c>CourseSection</c> objects in a <c>CourseSectionCollection</c> object to update.</param>
	/// <remarks>
	///		This function will only update entity objects marked as dirty
	///		and do not have an primary key value of 0.
	///		Upon updating the objects, each dirty object will have the public
	///		method <c>Object.AcceptChanges()</c> called to make it clean.
	/// 	After updating the datasource, the <c>CourseSection</c> objects will be updated
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns the number of successful update .</returns>
	public int Update(string connectionString, CourseSectionCollection entityCollection)
	{	
		int number = 0;
		foreach (CourseSection entity in entityCollection)
		{
			if ((entity.IsDirty) && !(entity.IsNew))
			{
				if ( Update(connectionString, entity) )
				{
					number++;
				}
			}
		}
		return number;
	}
	
	
	/// <summary>
	/// 	Update existing rows in the datasource.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="entityCollection"><c>CourseSection</c> objects in a <c>CourseSectionCollection</c> object to update.</param>
	/// <remarks>
	///		This function will only update entity objects marked as dirty
	///		and do not have an primary key value of 0.
	///		Upon updating the objects, each dirty object will have the public
	///		method <c>Object.AcceptChanges()</c> called to make it clean.
	/// 	After updating the datasource, the <c>CourseSection</c> objects will be updated
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns the number of successful update .</returns>
	public int Update(TransactionManager transactionManager, CourseSectionCollection entityCollection)
	{
		int number = 0;
		foreach (CourseSection entity in entityCollection)
		{
			if ((entity.IsDirty) && !(entity.IsNew))
			{
				if ( Update(transactionManager, entity) )
				{
					number++;
				}
			}
		}
		return number;
	}

	/// <summary>
	/// 	Update an existing row in the datasource.
	/// </summary>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <param name="entity">CourseSection object to update.</param>
	/// <remarks>After updating the datasource, the CourseSection object will be updated
	/// to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public bool Update(string connectionString, CourseSection entity)
	{	
		return Update(null, connectionString, entity);
	}
	
	
	/// <summary>
	/// 	Update an existing row in the datasource.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="entity">CourseSection object to update.</param>
	/// <remarks>After updating the datasource, the CourseSection object will be updated
	/// to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public bool Update(TransactionManager transactionManager, CourseSection entity)
	{
		if (transactionManager.IsOpen)
			return Update(transactionManager, null, entity);
		else
			return Update(null, transactionManager.ConnectionString, entity);
	}
	
	
	/// <summary>
	/// 	Update an existing row in the datasource.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="connectionString">Connection string to datasource.</param>
	/// <param name="entity">CourseSection object to update.</param>
	/// <remarks>After updating the datasource, the CourseSection object will be updated
	/// to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	protected bool Update(TransactionManager transactionManager, string connectionString, CourseSection entity)
	{
		//Declare variables
		//IDataParameterCollection parameters;
		SqlDataReader reader;
		int result = 0;
		//Get Parameters
		//if (transactionManager != null)
		//	parameters = SqlHelperParameterCache.GetSpParameterSet(transactionManager.ConnectionString, "prc_CourseSection_Update");
		//else
		//	parameters = SqlHelperParameterCache.GetSpParameterSet(connectionString, "prc_CourseSection_Update");
		//Assign parameters values to corresponding entity values
		//AssignUpdateParameters(parameters, entity);
		
		
		//Get Reader
		if (transactionManager != null)
			reader = SqlHelper.ExecuteReader(transactionManager.TransactionObject, "prc_CourseSection_Update",
				entity.ID,entity.Capacity,entity.ChangeStamp,entity.ClassID,entity.CourseID,entity.Description,entity.Status,entity.Title,entity.Type);
		else
			reader = SqlHelper.ExecuteReader(connectionString, "prc_CourseSection_Update", 
				entity.ID,entity.Capacity,entity.ChangeStamp,entity.ClassID,entity.CourseID,entity.Description,entity.Status,entity.Title,entity.Type);
			
		Debug.WriteLine("CourseSectionRepository-Update Affected " + reader.RecordsAffected + " records.");
		if (reader.RecordsAffected > 0)
		{
			RefreshEntity(reader, entity);
			result = reader.RecordsAffected;
		}
		else
		{
			//must always close the connection
			reader.Close();
			DBConcurrencyException conflict = new DBConcurrencyException("Concurrency exception");
			conflict.ModifiedRecord = entity;
			CourseSectionCollection dsrecord;
			//Get record from Datasource
			if (transactionManager != null)
				dsrecord = CourseSectionRepository.Current.GetByID(this.transactionManager, entity.ID);
			else
				dsrecord = CourseSectionRepository.Current.GetByID(connectionString, entity.ID);
			if(dsrecord.Count > 0)
				conflict.DatasourceRecord = dsrecord[0];
			throw conflict;
		}
		return Convert.ToBoolean(result);
	}

	
	
	/// <summary>
	/// Assigns the update parameters from an to a <see cref="CourseSection"/> instance to an <see cref="SqlParameter"/> array.
	/// </summary>
	/// <param name="parameters">The <see cref="SqlParameter"/> array.</param>
	/// <param name="entity">The <see cref="CourseSection"/> instance.</param>
	//protected void AssignUpdateParameters(IDataParameterCollection paramCollection, CourseSection entity)
	//{
	//}
	
	#endregion
	
	
	#region "Save Functions"
	
	/// <summary>
	/// 	Updates, Inserts rows in the datasource.
	/// </summary>
	/// <param name="entityCollection"><c>CourseSection</c> objects in a <c>CourseSectionCollection</c> object to update.</param>
	/// <remarks>
	/// 	After updating the datasource, the <c>CourseSection</c> objects will be updated or inserted
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public void Save(CourseSectionCollection entityCollection)
	{
		if(UseTransaction())
		{
			Save(this.transactionManager, entityCollection);
		}
		else
		{
			Save(this.connectionString, entityCollection);
		}
	}
	

		
	
	/// <summary>
	/// 	Updates, Inserts rows in the datasource.
	/// </summary>
	/// <param name="connectionString">Connection String to Datasource.</param>
	/// <param name="entity">CourseSection object to update.</param>
	/// <remarks>
	/// 	After updating the datasource, the <c>CourseSection</c> objects will be updated or inserted
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public void Save(string connectionString, CourseSection entity)
	{		
		if (entity.IsDeleted)
			Delete(connectionString, entity);
		else if ((entity.IsDirty) && !(entity.IsNew))
			Update(connectionString, entity);
		else if (entity.IsNew)
			Insert(connectionString, entity);
	}



	/// <summary>
	/// 	Updates, Inserts rows in the datasource.
	/// </summary>
	/// <param name="connectionString">Connection String to Datasource.</param>
	/// <param name="entityCollection"><c>CourseSection</c> objects in a <c>CourseSectionCollection</c> object to update.</param>
	/// <remarks>
	/// 	After updating the datasource, the <c>CourseSection</c> objects will be updated or inserted
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public void Save(string connectionString, CourseSectionCollection entityCollection)
	{
		foreach (CourseSection entity in entityCollection)
		{			
			Save(connectionString, entity);
		}
	}
	
	
	
	
	/// <summary>
	/// 	Updates, Inserts rows in the datasource.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="entity"><c>CourseSection</c> objects in a <c>CourseSectionCollection</c> object to update.</param>
	/// <remarks>
	/// 	After updating the datasource, the <c>CourseSection</c> objects will be updated or inserted
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public void Save(TransactionManager transactionManager, CourseSection entity)
	{		
		if (entity.IsDeleted)
		{
			Delete(transactionManager, entity);
		}
		if ((entity.IsDirty) && !(entity.IsNew))
		{
			Update(transactionManager, entity);
		}
		else if (entity.IsNew)
		{
			Insert(transactionManager, entity);
		}
	}
	
	
	/// <summary>
	/// 	Updates, Inserts rows in the datasource.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
	/// <param name="entityCollection"><c>CourseSection</c> objects in a <c>CourseSectionCollection</c> object to update.</param>
	/// <remarks>
	/// 	After updating the datasource, the <c>CourseSection</c> objects will be updated or inserted
	/// 	to refelect any changes made by the datasource. (ie: identity columns)</remarks>
	/// <returns>Returns true if operation is successful.</returns>
	public void Save(TransactionManager transactionManager, CourseSectionCollection entityCollection)
	{
		foreach (CourseSection entity in entityCollection)
		{
			Save(transactionManager, entity);
		}
	}
	#endregion
	

	#region "Helper Functions"

	///<summary>
	/// Fill an CourseSectionCollection From a DataSet
	///</summary>
	/// <param name="dataSet">the DataSet</param>
	/// <param name="rows">The collection to fill</param>
	/// <param name="start">Start row</param>
	/// <param name="pagelen">number of row.</param>
	///<returns>A <see chref="CourseSectionCollection"/> object.</returns>
	protected CourseSectionCollection Fill(DataSet dataSet, CourseSectionCollection rows, int start, int pagelen)
	{
		int recordnum = 0;
		
		System.Collections.IEnumerator dataRows =  dataSet.Tables[0].Rows.GetEnumerator();
		
		while (dataRows.MoveNext() && (pagelen != 0))
		{
			if(recordnum >= start)
			{
				DataRow row = (DataRow)dataRows.Current;
			
				CourseSection c = new CourseSection();
				c.ID = (Convert.IsDBNull(row["ID"]))?(int)0:(System.Int32)row["ID"];
				c.Title = (Convert.IsDBNull(row["Title"]))?string.Empty:(System.String)row["Title"];
				c.Description = (Convert.IsDBNull(row["Description"]))?string.Empty:(System.String)row["Description"];
				c.Capacity = (Convert.IsDBNull(row["Capacity"]))?(int)0:(System.Int32)row["Capacity"];
				c.CourseID = (Convert.IsDBNull(row["CourseID"]))?(int)0:(System.Int32)row["CourseID"];
				c.ClassID = (Convert.IsDBNull(row["ClassID"]))?string.Empty:(System.String)row["ClassID"];
				c.Status = (Convert.IsDBNull(row["Status"]))?(int)0:(System.Int32)row["Status"];
				c.Type = (Convert.IsDBNull(row["Type"]))?(int)0:(System.Int32)row["Type"];
				c.ChangeStamp = (Convert.IsDBNull(row["ChangeStamp"]))?DateTime.MinValue:(System.DateTime)row["ChangeStamp"];
				rows.Add(c);
				pagelen -= 1;
			}
			recordnum += 1;
		}
		return rows;
	}

	
	///<summary>
	/// Fill an CourseSectionCollection From a DataReader.
	///</summary>
	/// <param name="reader">Datareader</param>
	/// <param name="rows">The collection to fill</param>
	/// <param name="start">Start row</param>
	/// <param name="pagelen">number of row.</param>
	///<returns>a <see cref="CourseSectionCollection"/></returns>
	protected CourseSectionCollection Fill(SqlDataReader reader, CourseSectionCollection rows, int start, int pagelen)
	{
		int recordnum = 0;
		while (reader.Read() && (pagelen != 0))
		{
			if(recordnum >= start)
			{
				CourseSection c = new CourseSection();
				c.ID = (Convert.IsDBNull(reader["ID"]))?(int)0:(System.Int32)reader["ID"];
				c.Title = (Convert.IsDBNull(reader["Title"]))?string.Empty:(System.String)reader["Title"];
				c.Description = (Convert.IsDBNull(reader["Description"]))?string.Empty:(System.String)reader["Description"];
				c.Capacity = (Convert.IsDBNull(reader["Capacity"]))?(int)0:(System.Int32)reader["Capacity"];
				c.CourseID = (Convert.IsDBNull(reader["CourseID"]))?(int)0:(System.Int32)reader["CourseID"];
				c.ClassID = (Convert.IsDBNull(reader["ClassID"]))?string.Empty:(System.String)reader["ClassID"];
				c.Status = (Convert.IsDBNull(reader["Status"]))?(int)0:(System.Int32)reader["Status"];
				c.Type = (Convert.IsDBNull(reader["Type"]))?(int)0:(System.Int32)reader["Type"];
				c.ChangeStamp = (Convert.IsDBNull(reader["ChangeStamp"]))?DateTime.MinValue:(System.DateTime)reader["ChangeStamp"];
				c.AcceptChanges();
				rows.Add(c);
				pagelen -= 1;
			}
			recordnum += 1;
		}
		return rows;
	}
	
	
	/// <summary>
	/// Refreshes the <see cref="CourseSection"/> object from the <see cref="SqlDataReader"/>.
	/// </summary>
	/// <param name="reader">The <see cref="SqlDataReader"/> to read from.</param>
	/// <param name="entity">The <see cref="CourseSection"/> object.</param>
	protected void RefreshEntity(SqlDataReader reader, CourseSection entity)
	{
		reader.Read();
		entity.ID = (Convert.IsDBNull(reader["ID"]))?(int)0:(System.Int32)reader["ID"];
		entity.Title = (Convert.IsDBNull(reader["Title"]))?string.Empty:(System.String)reader["Title"];
		entity.Description = (Convert.IsDBNull(reader["Description"]))?string.Empty:(System.String)reader["Description"];
		entity.Capacity = (Convert.IsDBNull(reader["Capacity"]))?(int)0:(System.Int32)reader["Capacity"];
		entity.CourseID = (Convert.IsDBNull(reader["CourseID"]))?(int)0:(System.Int32)reader["CourseID"];
		entity.ClassID = (Convert.IsDBNull(reader["ClassID"]))?string.Empty:(System.String)reader["ClassID"];
		entity.Status = (Convert.IsDBNull(reader["Status"]))?(int)0:(System.Int32)reader["Status"];
		entity.Type = (Convert.IsDBNull(reader["Type"]))?(int)0:(System.Int32)reader["Type"];
		entity.ChangeStamp = (Convert.IsDBNull(reader["ChangeStamp"]))?DateTime.MinValue:(System.DateTime)reader["ChangeStamp"];
		reader.Close();

		entity.AcceptChanges();
	}
	
	
	/// <summary>
	/// Indicates if a transaction is currently used.
	/// </summary>
	/// <returns></returns>
	protected bool UseTransaction()
	{
		return UseTransaction(this.transactionManager);
	}
	
	
	
	/// <summary>
	/// Indicates if a transaction is currently used.
	/// </summary>
	/// <param name="transactionManager"><see cref="TransactionManager"/> object.</param>
	/// <returns></returns>
	protected bool UseTransaction(TransactionManager transactionManager)
	{
		if (transactionManager != null)
		{
			if (transactionManager.IsOpen)
				return true;
		}
		return false;
	}
	#endregion "Helper Functions"
	
	}//end class
} // end namespace

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Omar Al Zabir
Architect BT, UK (ex British Telecom)
United Kingdom United Kingdom

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.141223.1 | Last Updated 17 Aug 2005
Article Copyright 2005 by Omar Al Zabir
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid