// ========================================================================
// Copyright 2007 - Volian Enterprises, Inc. All rights reserved.          
// Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
// ------------------------------------------------------------------------
// $Workfile: $     $Revision: $                                           
// $Author: $   $Date: $                                                   
//                                                                         
// $History: $                                                             
// ========================================================================
using System;
using System.Data;
using System.Data.SqlClient;
using Csla;
using Csla.Data;
using System.Configuration;
using System.IO;
using System.ComponentModel;
using System.Collections.Generic;
using Csla.Validation;
namespace VEPROMS.CSLA.Library
{
	/// 
	///	Content Generated by MyGeneration using the CSLA Object Mapping template
	/// 
	[Serializable()]
	[TypeConverter(typeof(ContentConverter))]
	public partial class Content : BusinessBase, IDisposable, IVEHasBrokenRules
	{
		#region Log4Net
		private static readonly log4net.ILog _MyLog = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
		#endregion
		#region Refresh
		private List _RefreshContents = new List();
		private List _RefreshContentDetails = new List();
		private List _RefreshContentItems = new List();
		private List _RefreshContentParts = new List();
		private List _RefreshContentRoUsages = new List();
		private List _RefreshContentTransitions = new List();
		private void AddToRefreshList(List refreshContents, List refreshContentDetails, List refreshContentItems, List refreshContentParts, List refreshContentRoUsages, List refreshContentTransitions)
		{
			if (IsDirty)
				refreshContents.Add(this);
			if (_ContentDetails != null && _ContentDetails.IsDirty)
			{
				foreach (ContentDetail tmp in _ContentDetails)
				{
					if (tmp.IsDirty) refreshContentDetails.Add(tmp);
				}
			}
			if (_ContentItems != null && _ContentItems.IsDirty)
			{
				foreach (ContentItem tmp in _ContentItems)
				{
					if (tmp.IsDirty) refreshContentItems.Add(tmp);
				}
			}
			if (_ContentParts != null && _ContentParts.IsDirty)
			{
				foreach (ContentPart tmp in _ContentParts)
				{
					if (tmp.IsDirty) refreshContentParts.Add(tmp);
				}
			}
			if (_ContentRoUsages != null && _ContentRoUsages.IsDirty)
			{
				foreach (ContentRoUsage tmp in _ContentRoUsages)
				{
					if (tmp.IsDirty) refreshContentRoUsages.Add(tmp);
				}
			}
			if (_ContentTransitions != null && _ContentTransitions.IsDirty)
			{
				foreach (ContentTransition tmp in _ContentTransitions)
				{
					if (tmp.IsDirty) refreshContentTransitions.Add(tmp);
				}
			}
		}
		private void BuildRefreshList()
		{
			_RefreshContents = new List();
			_RefreshContentDetails = new List();
			_RefreshContentItems = new List();
			_RefreshContentParts = new List();
			_RefreshContentRoUsages = new List();
			_RefreshContentTransitions = new List();
			AddToRefreshList(_RefreshContents, _RefreshContentDetails, _RefreshContentItems, _RefreshContentParts, _RefreshContentRoUsages, _RefreshContentTransitions);
		}
		private void ProcessRefreshList()
		{
			foreach (Content tmp in _RefreshContents)
			{
				ContentInfo.Refresh(tmp);
				if (tmp._MyFormat != null) FormatInfo.Refresh(tmp._MyFormat);
			}
			foreach (ContentDetail tmp in _RefreshContentDetails)
			{
				DetailInfo.Refresh(tmp);
			}
			foreach (ContentItem tmp in _RefreshContentItems)
			{
				ItemInfo.Refresh(tmp);
			}
			foreach (ContentPart tmp in _RefreshContentParts)
			{
				PartInfo.Refresh(this, tmp);
			}
			foreach (ContentRoUsage tmp in _RefreshContentRoUsages)
			{
				RoUsageInfo.Refresh(tmp);
			}
			foreach (ContentTransition tmp in _RefreshContentTransitions)
			{
				TransitionInfo.Refresh(tmp);
			}
		}
		#endregion
		#region Collection
		private static List _CacheList = new List();
		protected static void AddToCache(Content content)
		{
			if (!_CacheList.Contains(content)) _CacheList.Add(content); // In AddToCache
		}
		protected static void RemoveFromCache(Content content)
		{
			while (_CacheList.Contains(content)) _CacheList.Remove(content); // In RemoveFromCache
		}
		private static Dictionary> _CacheByPrimaryKey = new Dictionary>();
		private static void ConvertListToDictionary()
		{
			List remove = new List();
			foreach (Content tmp in _CacheList)
			{
				if (!_CacheByPrimaryKey.ContainsKey(tmp.ContentID.ToString()))
				{
					_CacheByPrimaryKey[tmp.ContentID.ToString()] = new List(); // Add new list for PrimaryKey
				}
				_CacheByPrimaryKey[tmp.ContentID.ToString()].Add(tmp); // Add to Primary Key list
				remove.Add(tmp);
			}
			foreach (Content tmp in remove)
				RemoveFromCache(tmp);
		}
		protected static Content GetCachedByPrimaryKey(int contentID)
		{
			ConvertListToDictionary();
			string key = contentID.ToString();
			if (_CacheByPrimaryKey.ContainsKey(key)) return _CacheByPrimaryKey[key][0];
			return null;
		}
		#endregion
		#region Business Methods
		private string _ErrorMessage = string.Empty;
		public string ErrorMessage
		{
			get { return _ErrorMessage; }
		}
		private static int _nextContentID = -1;
		public static int NextContentID
		{
			get { return _nextContentID--; }
		}
		private int _ContentID;
		[System.ComponentModel.DataObjectField(true, true)]
		public int ContentID
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("ContentID", true);
				return _ContentID;
			}
		}
		private string _Number = string.Empty;
		public string Number
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("Number", true);
				return _Number;
			}
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			set
			{
				CanWriteProperty("Number", true);
				if (value == null) value = string.Empty;
				if (_Number != value)
				{
					_Number = value;
					PropertyHasChanged();
				}
			}
		}
		private string _Text = string.Empty;
		public string Text
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("Text", true);
				return _Text;
			}
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			set
			{
				CanWriteProperty("Text", true);
				if (value == null) value = string.Empty;
				if (_Text != value)
				{
					_Text = value;
					PropertyHasChanged();
				}
			}
		}
		private int? _Type;
		/// 
		/// 0 - Procedure, 10000 - Section, 20000 Step
		/// 
		public int? Type
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("Type", true);
				return _Type;
			}
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			set
			{
				CanWriteProperty("Type", true);
				if (_Type != value)
				{
					_Type = value;
					PropertyHasChanged();
				}
			}
		}
		private int? _FormatID;
		public int? FormatID
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("FormatID", true);
				if (_MyFormat != null) _FormatID = _MyFormat.FormatID;
				return _FormatID;
			}
		}
		private Format _MyFormat;
		public Format MyFormat
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("MyFormat", true);
				if (_MyFormat == null && _FormatID != null) _MyFormat = Format.Get((int)_FormatID);
				return _MyFormat;
			}
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			set
			{
				CanWriteProperty("MyFormat", true);
				if ((_MyFormat == null ? _FormatID : (int?)_MyFormat.FormatID) != (value == null ? null : (int?)value.FormatID))
				{
					_MyFormat = value;
					_FormatID = (value == null ? null : (int?)value.FormatID);
					PropertyHasChanged();
				}
			}
		}
		private string _Config = string.Empty;
		public string Config
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("Config", true);
				return _Config;
			}
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			set
			{
				CanWriteProperty("Config", true);
				if (value == null) value = string.Empty;
				if (_Config != value)
				{
					_Config = value;
					PropertyHasChanged();
				}
			}
		}
		private DateTime _DTS = new DateTime();
		public DateTime DTS
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("DTS", true);
				return _DTS;
			}
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			set
			{
				CanWriteProperty("DTS", true);
				if (_DTS != value)
				{
					_DTS = value;
					PropertyHasChanged();
				}
			}
		}
		private string _UserID = string.Empty;
		public string UserID
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("UserID", true);
				return _UserID;
			}
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			set
			{
				CanWriteProperty("UserID", true);
				if (value == null) value = string.Empty;
				if (_UserID != value)
				{
					_UserID = value;
					PropertyHasChanged();
				}
			}
		}
		private byte[] _LastChanged = new byte[8];//timestamp
		private int _ContentDetailCount = 0;
		/// 
		/// Count of ContentDetails for this Content
		/// 
		public int ContentDetailCount
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("ContentDetailCount", true);
				return _ContentDetailCount;
			}
		}
		private ContentDetails _ContentDetails = null;
		/// 
		/// Related Field
		/// 
		[TypeConverter(typeof(ContentDetailsConverter))]
		public ContentDetails ContentDetails
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("ContentDetails", true);
				if (_ContentDetailCount > 0 && _ContentDetails == null)
					_ContentDetails = ContentDetails.GetByContentID(ContentID);
				else if (_ContentDetails == null)
					_ContentDetails = ContentDetails.New();
				return _ContentDetails;
			}
		}
		private int _ContentEntryCount = 0;
		/// 
		/// Count of ContentEntries for this Content
		/// 
		public int ContentEntryCount
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("ContentEntryCount", true);
				return _ContentEntryCount;
			}
		}
		private Entry _MyEntry = null;
		/// 
		/// Related Field
		/// 
		[TypeConverter(typeof(EntryConverter))]
		public Entry MyEntry
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("MyEntry", true);
				if (_MyEntry == null) _MyEntry = Entry.New(this);
				return _MyEntry;
			}
		}
		private int _ContentItemCount = 0;
		/// 
		/// Count of ContentItems for this Content
		/// 
		public int ContentItemCount
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("ContentItemCount", true);
				return _ContentItemCount;
			}
		}
		private ContentItems _ContentItems = null;
		/// 
		/// Related Field
		/// 
		[TypeConverter(typeof(ContentItemsConverter))]
		public ContentItems ContentItems
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("ContentItems", true);
				if (_ContentItemCount > 0 && _ContentItems == null)
					_ContentItems = ContentItems.GetByContentID(ContentID);
				else if (_ContentItems == null)
					_ContentItems = ContentItems.New();
				return _ContentItems;
			}
		}
		private int _ContentPartCount = 0;
		/// 
		/// Count of ContentParts for this Content
		/// 
		public int ContentPartCount
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("ContentPartCount", true);
				return _ContentPartCount;
			}
		}
		private ContentParts _ContentParts = null;
		/// 
		/// Related Field
		/// 
		[TypeConverter(typeof(ContentPartsConverter))]
		public ContentParts ContentParts
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("ContentParts", true);
				if (_ContentPartCount > 0 && _ContentParts == null)
					_ContentParts = ContentParts.GetByContentID(ContentID);
				else if (_ContentParts == null)
					_ContentParts = ContentParts.New();
				return _ContentParts;
			}
		}
		private int _ContentRoUsageCount = 0;
		/// 
		/// Count of ContentRoUsages for this Content
		/// 
		public int ContentRoUsageCount
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("ContentRoUsageCount", true);
				return _ContentRoUsageCount;
			}
		}
		private ContentRoUsages _ContentRoUsages = null;
		/// 
		/// Related Field
		/// 
		[TypeConverter(typeof(ContentRoUsagesConverter))]
		public ContentRoUsages ContentRoUsages
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("ContentRoUsages", true);
				if (_ContentRoUsageCount > 0 && _ContentRoUsages == null)
					_ContentRoUsages = ContentRoUsages.GetByContentID(ContentID);
				else if (_ContentRoUsages == null)
					_ContentRoUsages = ContentRoUsages.New();
				return _ContentRoUsages;
			}
		}
		private int _ContentTransitionCount = 0;
		/// 
		/// Count of ContentTransitions for this Content
		/// 
		public int ContentTransitionCount
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("ContentTransitionCount", true);
				return _ContentTransitionCount;
			}
		}
		private ContentTransitions _ContentTransitions = null;
		/// 
		/// Related Field
		/// 
		[TypeConverter(typeof(ContentTransitionsConverter))]
		public ContentTransitions ContentTransitions
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("ContentTransitions", true);
				if (_ContentTransitionCount > 0 && _ContentTransitions == null)
					_ContentTransitions = ContentTransitions.GetByFromID(ContentID);
				else if (_ContentTransitions == null)
					_ContentTransitions = ContentTransitions.New();
				return _ContentTransitions;
			}
		}
		private int _ContentZContentCount = 0;
		/// 
		/// Count of ContentZContents for this Content
		/// 
		public int ContentZContentCount
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("ContentZContentCount", true);
				return _ContentZContentCount;
			}
		}
		private ZContent _MyZContent = null;
		/// 
		/// Related Field
		/// 
		[TypeConverter(typeof(ZContentConverter))]
		public ZContent MyZContent
		{
			[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.NoInlining)]
			get
			{
				CanReadProperty("MyZContent", true);
				if (_MyZContent == null) _MyZContent = ZContent.New(this);
				return _MyZContent;
			}
		}
		public override bool IsDirty
		{
			get { return base.IsDirty || (_ContentDetails == null ? false : _ContentDetails.IsDirty) || (_MyEntry == null ? false : _MyEntry.IsDirty) || (_ContentItems == null ? false : _ContentItems.IsDirty) || (_ContentParts == null ? false : _ContentParts.IsDirty) || (_ContentRoUsages == null ? false : _ContentRoUsages.IsDirty) || (_ContentTransitions == null ? false : _ContentTransitions.IsDirty) || (_MyZContent == null ? false : _MyZContent.IsDirty) || (_MyFormat == null ? false : _MyFormat.IsDirty); }
		}
		public override bool IsValid
		{
			get { return (IsNew && !IsDirty ? true : base.IsValid) && (_ContentDetails == null ? true : _ContentDetails.IsValid) && (_MyEntry == null ? true : _MyEntry.IsValid) && (_ContentItems == null ? true : _ContentItems.IsValid) && (_ContentParts == null ? true : _ContentParts.IsValid) && (_ContentRoUsages == null ? true : _ContentRoUsages.IsValid) && (_ContentTransitions == null ? true : _ContentTransitions.IsValid) && (_MyZContent == null ? true : _MyZContent.IsValid) && (_MyFormat == null ? true : _MyFormat.IsValid); }
		}
		// TODO: Replace base Content.ToString function as necessary
		/// 
		/// Overrides Base ToString
		/// 
		/// A string representation of current Content
		//public override string ToString()
		//{
		//  return base.ToString();
		//}
		// TODO: Check Content.GetIdValue to assure that the ID returned is unique
		/// 
		/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
		/// 
		/// A Unique ID for the current Content
		protected override object GetIdValue()
		{
			return _ContentID;
		}
		#endregion
		#region ValidationRules
		[NonSerialized]
		private bool _CheckingBrokenRules = false;
		public IVEHasBrokenRules HasBrokenRules
		{
			get
			{
				if (_CheckingBrokenRules) return null;
				if ((IsDirty || !IsNew) && BrokenRulesCollection.Count > 0) return this;
				try
				{
					_CheckingBrokenRules = true;
					IVEHasBrokenRules hasBrokenRules = null;
					if (_ContentItems != null && (hasBrokenRules = _ContentItems.HasBrokenRules) != null) return hasBrokenRules;
					if (_ContentDetails != null && (hasBrokenRules = _ContentDetails.HasBrokenRules) != null) return hasBrokenRules;
					if (_MyEntry != null && (hasBrokenRules = _MyEntry.HasBrokenRules) != null) return hasBrokenRules;
					if (_ContentParts != null && (hasBrokenRules = _ContentParts.HasBrokenRules) != null) return hasBrokenRules;
					if (_ContentRoUsages != null && (hasBrokenRules = _ContentRoUsages.HasBrokenRules) != null) return hasBrokenRules;
					if (_ContentTransitions != null && (hasBrokenRules = _ContentTransitions.HasBrokenRules) != null) return hasBrokenRules;
					if (_MyZContent != null && (hasBrokenRules = _MyZContent.HasBrokenRules) != null) return hasBrokenRules;
					if (_MyFormat != null && (hasBrokenRules = _MyFormat.HasBrokenRules) != null) return hasBrokenRules;
					return hasBrokenRules;
				}
				finally
				{
					_CheckingBrokenRules = false;
				}
			}
		}
		public BrokenRulesCollection BrokenRules
		{
			get
			{
				IVEHasBrokenRules hasBrokenRules = HasBrokenRules;
				if (this.Equals(hasBrokenRules)) return BrokenRulesCollection;
				return (hasBrokenRules != null ? hasBrokenRules.BrokenRules : null);
			}
		}
		protected override void AddBusinessRules()
		{
			ValidationRules.AddRule(
				Csla.Validation.CommonRules.StringMaxLength,
				new Csla.Validation.CommonRules.MaxLengthRuleArgs("Number", 30));
			ValidationRules.AddRule(
				Csla.Validation.CommonRules.StringMaxLength,
				new Csla.Validation.CommonRules.MaxLengthRuleArgs("Text", 1073741823));
			ValidationRules.AddRule(
				Csla.Validation.CommonRules.StringMaxLength,
				new Csla.Validation.CommonRules.MaxLengthRuleArgs("Config", 1073741823));
			ValidationRules.AddRule(
				Csla.Validation.CommonRules.StringRequired, "UserID");
			ValidationRules.AddRule(
				Csla.Validation.CommonRules.StringMaxLength,
				new Csla.Validation.CommonRules.MaxLengthRuleArgs("UserID", 100));
			//ValidationRules.AddDependantProperty("x", "y");
			_ContentExtension.AddValidationRules(ValidationRules);
			// TODO:  Add other validation rules
		}
		protected override void AddInstanceBusinessRules()
		{
			_ContentExtension.AddInstanceValidationRules(ValidationRules);
			// TODO:  Add other validation rules
		}
		// Sample data comparison validation rule
		//private bool StartDateGTEndDate(object target, Csla.Validation.RuleArgs e)
		//{
		//	if (_started > _ended)
		//	{
		//		e.Description = "Start date can't be after end date";
		//		return false;
		//	}
		//	else
		//		return true;
		//}
		#endregion
		#region Authorization Rules
		protected override void AddAuthorizationRules()
		{
			//TODO: Who can read/write which fields
			//AuthorizationRules.AllowRead(ContentID, "");
			//AuthorizationRules.AllowRead(Number, "");
			//AuthorizationRules.AllowRead(Text, "");
			//AuthorizationRules.AllowRead(Type, "");
			//AuthorizationRules.AllowRead(FormatID, "");
			//AuthorizationRules.AllowRead(Config, "");
			//AuthorizationRules.AllowRead(DTS, "");
			//AuthorizationRules.AllowRead(UserID, "");
			//AuthorizationRules.AllowWrite(Number, "");
			//AuthorizationRules.AllowWrite(Text, "");
			//AuthorizationRules.AllowWrite(Type, "");
			//AuthorizationRules.AllowWrite(FormatID, "");
			//AuthorizationRules.AllowWrite(Config, "");
			//AuthorizationRules.AllowWrite(DTS, "");
			//AuthorizationRules.AllowWrite(UserID, "");
			_ContentExtension.AddAuthorizationRules(AuthorizationRules);
		}
		protected override void AddInstanceAuthorizationRules()
		{
			//TODO: Who can read/write which fields
			_ContentExtension.AddInstanceAuthorizationRules(AuthorizationRules);
		}
		public static bool CanAddObject()
		{
			// TODO: Can Add Authorization
			//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
			return true;
		}
		public static bool CanGetObject()
		{
			// TODO: CanGet Authorization
			return true;
		}
		public static bool CanDeleteObject()
		{
			// TODO: CanDelete Authorization
			//bool result = false;
			//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
			//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
			//return result;
			return true;
		}
		/// 
		/// determines if related records (Foreign Keys) will keep this Item from being deleted
		/// 
		public bool CanDelete
		{
			get
			{
				// Check to make sure that there are not any related records
				int usedByCount = 0;
				usedByCount += _ContentDetailCount;
				usedByCount += _ContentEntryCount;
				usedByCount += _ContentItemCount;
				usedByCount += _ContentPartCount;
				usedByCount += _ContentRoUsageCount;
				usedByCount += _ContentTransitionCount;
				usedByCount += _ContentZContentCount;
				return (usedByCount == 0);
			}
		}
		public static bool CanEditObject()
		{
			// TODO: CanEdit Authorization
			//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
			return true;
		}
		#endregion
		#region Factory Methods
		public int CurrentEditLevel
		{ get { return EditLevel; } }
		private static int _ContentUnique = 0;
		protected static int ContentUnique
		{ get { return ++_ContentUnique; } }
		private int _MyContentUnique = ContentUnique;
		public int MyContentUnique
		{ get { return _MyContentUnique; } }
		protected Content()
		{/* require use of factory methods */
			AddToCache(this);
		}
		public void Dispose()
		{
			RemoveFromDictionaries();
		}
		private void RemoveFromDictionaries()
		{
			RemoveFromCache(this);
			if (_CacheByPrimaryKey.ContainsKey(ContentID.ToString()))
			{
				List listContent = _CacheByPrimaryKey[ContentID.ToString()]; // Get the list of items
				while (listContent.Contains(this)) listContent.Remove(this); // Remove the item from the list
				if (listContent.Count == 0) //If there are no items left in the list
					_CacheByPrimaryKey.Remove(ContentID.ToString()); // remove the list
			}
		}
		public static Content New()
		{
			if (!CanAddObject())
				throw new System.Security.SecurityException("User not authorized to add a Content");
			try
			{
				return DataPortal.Create();
			}
			catch (Exception ex)
			{
				throw new DbCslaException("Error on Content.New", ex);
			}
		}
		public static Content New(string number, string text, int? type, Format myFormat, string config, DateTime dts, string userID)
		{
			Content tmp = Content.New();
			tmp.Number = number;
			tmp.Text = text;
			tmp.Type = type;
			tmp.MyFormat = myFormat;
			tmp.Config = config;
			tmp.DTS = dts;
			tmp.UserID = userID;
			return tmp;
		}
		public static Content MakeContent(string number, string text, int? type, Format myFormat, string config, DateTime dts, string userID)
		{
			Content tmp = Content.New(number, text, type, myFormat, config, dts, userID);
			if (tmp.IsSavable)
			{
				Content tmp2 = tmp;
				tmp = tmp2.Save();
				tmp2.Dispose();
			}
			else
			{
				Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
				tmp._ErrorMessage = "Failed Validation:";
				foreach (Csla.Validation.BrokenRule br in brc)
				{
					tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName;
				}
			}
			return tmp;
		}
		public static Content New(string number, string text, int? type, Format myFormat, string config)
		{
			Content tmp = Content.New();
			tmp.Number = number;
			tmp.Text = text;
			tmp.Type = type;
			tmp.MyFormat = myFormat;
			tmp.Config = config;
			return tmp;
		}
		public static Content MakeContent(string number, string text, int? type, Format myFormat, string config)
		{
			Content tmp = Content.New(number, text, type, myFormat, config);
			if (tmp.IsSavable)
			{
				Content tmp2 = tmp;
				tmp = tmp2.Save();
				tmp2.Dispose();
			}
			else
			{
				Csla.Validation.BrokenRulesCollection brc = tmp.ValidationRules.GetBrokenRules();
				tmp._ErrorMessage = "Failed Validation:";
				foreach (Csla.Validation.BrokenRule br in brc)
				{
					tmp._ErrorMessage += "\r\n\tFailure: " + br.RuleName;
				}
			}
			return tmp;
		}
		public static Content Get(int contentID)
		{
			if (!CanGetObject())
				throw new System.Security.SecurityException("User not authorized to view a Content");
			try
			{
				Content tmp = GetCachedByPrimaryKey(contentID);
				if (tmp == null)
				{
					tmp = DataPortal.Fetch(new PKCriteria(contentID));
					AddToCache(tmp);
				}
				if (tmp.ErrorMessage == "No Record Found") 
				{
					tmp.Dispose(); // Clean-up Content
					tmp = null;
				}
				return tmp;
			}
			catch (Exception ex)
			{
				throw new DbCslaException("Error on Content.Get", ex);
			}
		}
		public static Content Get(SafeDataReader dr)
		{
			if (dr.Read()) return new Content(dr);
			return null;
		}
		internal Content(SafeDataReader dr)
		{
			ReadData(dr);
		}
		public static void Delete(int contentID)
		{
			if (!CanDeleteObject())
				throw new System.Security.SecurityException("User not authorized to remove a Content");
			try
			{
				DataPortal.Delete(new PKCriteria(contentID));
			}
			catch (Exception ex)
			{
				throw new DbCslaException("Error on Content.Delete", ex);
			}
		}
		public override Content Save()
		{
			if (IsDeleted && !CanDeleteObject())
				throw new System.Security.SecurityException("User not authorized to remove a Content");
			else if (IsNew && !CanAddObject())
				throw new System.Security.SecurityException("User not authorized to add a Content");
			else if (!CanEditObject())
				throw new System.Security.SecurityException("User not authorized to update a Content");
			try
			{
				BuildRefreshList();
				Content content = base.Save();
				RemoveFromDictionaries(); // if save is successful remove the previous Folder from the cache
				AddToCache(content);//Refresh the item in AllList
				ProcessRefreshList();
				return content;
			}
			catch (Exception ex)
			{
				throw new DbCslaException("Error on CSLA Save", ex);
			}
		}
		#endregion
		#region Data Access Portal
		[Serializable()]
		protected class PKCriteria
		{
			private int _ContentID;
			public int ContentID
			{ get { return _ContentID; } }
			public PKCriteria(int contentID)
			{
				_ContentID = contentID;
			}
		}
		// TODO: If Create needs to access DB - It should not be marked RunLocal
		[RunLocal()]
		private new void DataPortal_Create()
		{
			_ContentID = NextContentID;
			// Database Defaults
			_DTS = _ContentExtension.DefaultDTS;
			_UserID = _ContentExtension.DefaultUserID;
			// TODO: Add any defaults that are necessary
			ValidationRules.CheckRules();
		}
		private void ReadData(SafeDataReader dr)
		{
			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.ReadData", GetHashCode());
			try
			{
				_ContentID = dr.GetInt32("ContentID");
				_Number = dr.GetString("Number");
				_Text = dr.GetString("Text");
				_Type = (int?)dr.GetValue("Type");
				_FormatID = (int?)dr.GetValue("FormatID");
				_Config = dr.GetString("Config");
				_DTS = dr.GetDateTime("DTS");
				_UserID = dr.GetString("UserID");
				dr.GetBytes("LastChanged", 0, _LastChanged, 0, 8);
				_ContentDetailCount = dr.GetInt32("DetailCount");
				_ContentEntryCount = dr.GetInt32("EntryCount");
				_ContentItemCount = dr.GetInt32("ItemCount");
				_ContentPartCount = dr.GetInt32("PartCount");
				_ContentRoUsageCount = dr.GetInt32("RoUsageCount");
				_ContentTransitionCount = dr.GetInt32("TransitionCount");
				_ContentZContentCount = dr.GetInt32("ZContentCount");
				MarkOld();
			}
			catch (Exception ex)
			{
				if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.ReadData", ex);
				_ErrorMessage = ex.Message;
				throw new DbCslaException("Content.ReadData", ex);
			}
		}
		private void DataPortal_Fetch(PKCriteria criteria)
		{
			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Fetch", GetHashCode());
			try
			{
				using (SqlConnection cn = Database.VEPROMS_SqlConnection)
				{
					ApplicationContext.LocalContext["cn"] = cn;
					using (SqlCommand cm = cn.CreateCommand())
					{
						cm.CommandType = CommandType.StoredProcedure;
						cm.CommandText = "getContent";
						cm.Parameters.AddWithValue("@ContentID", criteria.ContentID);
						using (SafeDataReader dr = new SafeDataReader(cm.ExecuteReader()))
						{
							if (!dr.Read())
							{
								_ErrorMessage = "No Record Found";
								return;
							}
							ReadData(dr);
							// load child objects
							dr.NextResult();
							_ContentDetails = ContentDetails.Get(dr);
							// load child objects
							dr.NextResult();
							_MyEntry = Entry.Get(dr);
							// load child objects
							dr.NextResult();
							_ContentItems = ContentItems.Get(dr);
							// load child objects
							dr.NextResult();
							_ContentParts = ContentParts.Get(dr);
							// load child objects
							dr.NextResult();
							_ContentRoUsages = ContentRoUsages.Get(dr);
							// load child objects
							dr.NextResult();
							_ContentTransitions = ContentTransitions.Get(dr);
							// load child objects
							dr.NextResult();
							_MyZContent = ZContent.Get(dr);
						}
					}
					// removing of item only needed for local data portal
					if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client)
						ApplicationContext.LocalContext.Remove("cn");
				}
			}
			catch (Exception ex)
			{
				if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Fetch", ex);
				_ErrorMessage = ex.Message;
				throw new DbCslaException("Content.DataPortal_Fetch", ex);
			}
		}
		[Transactional(TransactionalTypes.TransactionScope)]
		protected override void DataPortal_Insert()
		{
			try
			{
				using (SqlConnection cn = Database.VEPROMS_SqlConnection)
				{
					ApplicationContext.LocalContext["cn"] = cn;
					SQLInsert();
					// removing of item only needed for local data portal
					if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client)
						ApplicationContext.LocalContext.Remove("cn");
				}
			}
			catch (Exception ex)
			{
				if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Insert", ex);
				_ErrorMessage = ex.Message;
				throw new DbCslaException("Content.DataPortal_Insert", ex);
			}
			finally
			{
				if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Insert", GetHashCode());
			}
		}
		[Transactional(TransactionalTypes.TransactionScope)]
		internal void SQLInsert()
		{
			if (!this.IsDirty) return;
			try
			{
				if (_MyFormat != null) _MyFormat.Update();
				SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
				using (SqlCommand cm = cn.CreateCommand())
				{
					cm.CommandType = CommandType.StoredProcedure;
					cm.CommandText = "addContent";
					// Input All Fields - Except Calculated Columns
					cm.Parameters.AddWithValue("@Number", _Number);
					cm.Parameters.AddWithValue("@Text", _Text);
					cm.Parameters.AddWithValue("@Type", _Type);
					cm.Parameters.AddWithValue("@FormatID", FormatID);
					cm.Parameters.AddWithValue("@Config", _Config);
					if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
					cm.Parameters.AddWithValue("@UserID", _UserID);
					// Output Calculated Columns
					SqlParameter param_ContentID = new SqlParameter("@newContentID", SqlDbType.Int);
					param_ContentID.Direction = ParameterDirection.Output;
					cm.Parameters.Add(param_ContentID);
					SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
					param_LastChanged.Direction = ParameterDirection.Output;
					cm.Parameters.Add(param_LastChanged);
					// TODO: Define any additional output parameters
					cm.ExecuteNonQuery();
					// Save all values being returned from the Procedure
					_ContentID = (int)cm.Parameters["@newContentID"].Value;
					_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
				}
				MarkOld();
				// update child objects
				if (_ContentItems != null) _ContentItems.Update(this);
				if (_ContentDetails != null) _ContentDetails.Update(this);
				if (_MyEntry != null) _MyEntry.Update(this);
				if (_ContentParts != null) _ContentParts.Update(this);
				if (_ContentRoUsages != null) _ContentRoUsages.Update(this);
				if (_ContentTransitions != null) _ContentTransitions.Update(this);
				if (_MyZContent != null) _MyZContent.Update(this);
				if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.SQLInsert", GetHashCode());
			}
			catch (Exception ex)
			{
				if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.SQLInsert", ex);
				_ErrorMessage = ex.Message;
				throw new DbCslaException("Content.SQLInsert", ex);
			}
		}
		[Transactional(TransactionalTypes.TransactionScope)]
		public static byte[] Add(SqlConnection cn, ref int contentID, string number, string text, int? type, Format myFormat, string config, DateTime dts, string userID)
		{
			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.Add", 0);
			try
			{
				using (SqlCommand cm = cn.CreateCommand())
				{
					cm.CommandType = CommandType.StoredProcedure;
					cm.CommandText = "addContent";
					// Input All Fields - Except Calculated Columns
					cm.Parameters.AddWithValue("@Number", number);
					cm.Parameters.AddWithValue("@Text", text);
					cm.Parameters.AddWithValue("@Type", type);
					if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.FormatID);
					cm.Parameters.AddWithValue("@Config", config);
					if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
					cm.Parameters.AddWithValue("@UserID", userID);
					// Output Calculated Columns
					SqlParameter param_ContentID = new SqlParameter("@newContentID", SqlDbType.Int);
					param_ContentID.Direction = ParameterDirection.Output;
					cm.Parameters.Add(param_ContentID);
					SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
					param_LastChanged.Direction = ParameterDirection.Output;
					cm.Parameters.Add(param_LastChanged);
					// TODO: Define any additional output parameters
					cm.ExecuteNonQuery();
					// Save all values being returned from the Procedure
					contentID = (int)cm.Parameters["@newContentID"].Value;
					return (byte[])cm.Parameters["@newLastChanged"].Value;
				}
			}
			catch (Exception ex)
			{
				if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.Add", ex);
				throw new DbCslaException("Content.Add", ex);
			}
		}
		[Transactional(TransactionalTypes.TransactionScope)]
		protected override void DataPortal_Update()
		{
			if (!IsDirty) return;	// If not dirty - nothing to do
			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Update", GetHashCode());
			try
			{
				using (SqlConnection cn = Database.VEPROMS_SqlConnection)
				{
					ApplicationContext.LocalContext["cn"] = cn;
					SQLUpdate();
					// removing of item only needed for local data portal
					if (ApplicationContext.ExecutionLocation == ApplicationContext.ExecutionLocations.Client)
						ApplicationContext.LocalContext.Remove("cn");
				}
			}
			catch (Exception ex)
			{
				if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Update", ex);
				_ErrorMessage = ex.Message;
				if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
			}
		}
		[Transactional(TransactionalTypes.TransactionScope)]
		internal void SQLUpdate()
		{
			if (!IsDirty) return;	// If not dirty - nothing to do
			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.SQLUpdate", GetHashCode());
			try
			{
				if (_MyFormat != null) _MyFormat.Update();
				SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
				if (base.IsDirty)
				{
					using (SqlCommand cm = cn.CreateCommand())
					{
						cm.CommandType = CommandType.StoredProcedure;
						cm.CommandText = "updateContent";
						// All Fields including Calculated Fields
						cm.Parameters.AddWithValue("@ContentID", _ContentID);
						cm.Parameters.AddWithValue("@Number", _Number);
						cm.Parameters.AddWithValue("@Text", _Text);
						cm.Parameters.AddWithValue("@Type", _Type);
						cm.Parameters.AddWithValue("@FormatID", FormatID);
						cm.Parameters.AddWithValue("@Config", _Config);
						if (_DTS.Year >= 1753 && _DTS.Year <= 9999) cm.Parameters.AddWithValue("@DTS", _DTS);
						cm.Parameters.AddWithValue("@UserID", _UserID);
						cm.Parameters.AddWithValue("@LastChanged", _LastChanged);
						// Output Calculated Columns
						SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
						param_LastChanged.Direction = ParameterDirection.Output;
						cm.Parameters.Add(param_LastChanged);
						// TODO: Define any additional output parameters
						cm.ExecuteNonQuery();
						// Save all values being returned from the Procedure
						_LastChanged = (byte[])cm.Parameters["@newLastChanged"].Value;
					}
				}
				MarkOld();
				// use the open connection to update child objects
				if (_ContentItems != null) _ContentItems.Update(this);
				if (_ContentDetails != null) _ContentDetails.Update(this);
				if (_MyEntry != null) _MyEntry.Update(this);
				if (_ContentParts != null) _ContentParts.Update(this);
				if (_ContentRoUsages != null) _ContentRoUsages.Update(this);
				if (_ContentTransitions != null) _ContentTransitions.Update(this);
				if (_MyZContent != null) _MyZContent.Update(this);
			}
			catch (Exception ex)
			{
				if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.SQLUpdate", ex);
				_ErrorMessage = ex.Message;
				if (!ex.Message.EndsWith("has been edited by another user.")) throw ex;
			}
		}
		internal void Update()
		{
			if (!this.IsDirty) return;
			if (base.IsDirty)
			{
				SqlConnection cn = (SqlConnection)ApplicationContext.LocalContext["cn"];
				if (IsNew)
					_LastChanged = Content.Add(cn, ref _ContentID, _Number, _Text, _Type, _MyFormat, _Config, _DTS, _UserID);
				else
					_LastChanged = Content.Update(cn, ref _ContentID, _Number, _Text, _Type, _MyFormat, _Config, _DTS, _UserID, ref _LastChanged);
				MarkOld();
			}
			if (_ContentItems != null) _ContentItems.Update(this);
			if (_ContentDetails != null) _ContentDetails.Update(this);
			if (_MyEntry != null) _MyEntry.Update(this);
			if (_ContentParts != null) _ContentParts.Update(this);
			if (_ContentRoUsages != null) _ContentRoUsages.Update(this);
			if (_ContentTransitions != null) _ContentTransitions.Update(this);
			if (_MyZContent != null) _MyZContent.Update(this);
		}
		[Transactional(TransactionalTypes.TransactionScope)]
		public static byte[] Update(SqlConnection cn, ref int contentID, string number, string text, int? type, Format myFormat, string config, DateTime dts, string userID, ref byte[] lastChanged)
		{
			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.Update", 0);
			try
			{
				using (SqlCommand cm = cn.CreateCommand())
				{
					cm.CommandType = CommandType.StoredProcedure;
					cm.CommandText = "updateContent";
					// Input All Fields - Except Calculated Columns
					cm.Parameters.AddWithValue("@ContentID", contentID);
					cm.Parameters.AddWithValue("@Number", number);
					cm.Parameters.AddWithValue("@Text", text);
					cm.Parameters.AddWithValue("@Type", type);
					if (myFormat != null) cm.Parameters.AddWithValue("@FormatID", myFormat.FormatID);
					cm.Parameters.AddWithValue("@Config", config);
					if (dts.Year >= 1753 && dts.Year <= 9999) cm.Parameters.AddWithValue("@DTS", dts);
					cm.Parameters.AddWithValue("@UserID", userID);
					cm.Parameters.AddWithValue("@LastChanged", lastChanged);
					// Output Calculated Columns
					SqlParameter param_LastChanged = new SqlParameter("@newLastChanged", SqlDbType.Timestamp);
					param_LastChanged.Direction = ParameterDirection.Output;
					cm.Parameters.Add(param_LastChanged);
					// TODO: Define any additional output parameters
					cm.ExecuteNonQuery();
					// Save all values being returned from the Procedure
					return (byte[])cm.Parameters["@newLastChanged"].Value;
				}
			}
			catch (Exception ex)
			{
				if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.Update", ex);
				throw new DbCslaException("Content.Update", ex);
			}
		}
		[Transactional(TransactionalTypes.TransactionScope)]
		protected override void DataPortal_DeleteSelf()
		{
			DataPortal_Delete(new PKCriteria(_ContentID));
		}
		[Transactional(TransactionalTypes.TransactionScope)]
		private void DataPortal_Delete(PKCriteria criteria)
		{
			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Delete", GetHashCode());
			try
			{
				using (SqlConnection cn = Database.VEPROMS_SqlConnection)
				{
					using (SqlCommand cm = cn.CreateCommand())
					{
						cm.CommandType = CommandType.StoredProcedure;
						cm.CommandText = "deleteContent";
						cm.Parameters.AddWithValue("@ContentID", criteria.ContentID);
						cm.ExecuteNonQuery();
					}
				}
			}
			catch (Exception ex)
			{
				if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Delete", ex);
				_ErrorMessage = ex.Message;
				throw new DbCslaException("Content.DataPortal_Delete", ex);
			}
		}
		[Transactional(TransactionalTypes.TransactionScope)]
		public static void Remove(SqlConnection cn, int contentID)
		{
			if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.Remove", 0);
			try
			{
				using (SqlCommand cm = cn.CreateCommand())
				{
					cm.CommandType = CommandType.StoredProcedure;
					cm.CommandText = "deleteContent";
					// Input PK Fields
					cm.Parameters.AddWithValue("@ContentID", contentID);
					// TODO: Define any additional output parameters
					cm.ExecuteNonQuery();
				}
			}
			catch (Exception ex)
			{
				if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.Remove", ex);
				throw new DbCslaException("Content.Remove", ex);
			}
		}
		#endregion
		#region Exists
		public static bool Exists(int contentID)
		{
			ExistsCommand result;
			try
			{
				result = DataPortal.Execute(new ExistsCommand(contentID));
				return result.Exists;
			}
			catch (Exception ex)
			{
				throw new DbCslaException("Error on Content.Exists", ex);
			}
		}
		[Serializable()]
		private class ExistsCommand : CommandBase
		{
			private int _ContentID;
			private bool _exists;
			public bool Exists
			{
				get { return _exists; }
			}
			public ExistsCommand(int contentID)
			{
				_ContentID = contentID;
			}
			protected override void DataPortal_Execute()
			{
				if (_MyLog.IsDebugEnabled) _MyLog.DebugFormat("[{0}] Content.DataPortal_Execute", GetHashCode());
				try
				{
					using (SqlConnection cn = Database.VEPROMS_SqlConnection)
					{
						cn.Open();
						using (SqlCommand cm = cn.CreateCommand())
						{
							cm.CommandType = CommandType.StoredProcedure;
							cm.CommandText = "existsContent";
							cm.Parameters.AddWithValue("@ContentID", _ContentID);
							int count = (int)cm.ExecuteScalar();
							_exists = (count > 0);
						}
					}
				}
				catch (Exception ex)
				{
					if (_MyLog.IsErrorEnabled) _MyLog.Error("Content.DataPortal_Execute", ex);
					throw new DbCslaException("Content.DataPortal_Execute", ex);
				}
			}
		}
		#endregion
		// Standard Default Code
		#region extension
		ContentExtension _ContentExtension = new ContentExtension();
		[Serializable()]
		partial class ContentExtension : extensionBase
		{
		}
		[Serializable()]
		class extensionBase
		{
			// Default Values
			public virtual DateTime DefaultDTS
			{
				get { return DateTime.Now; }
			}
			public virtual string DefaultUserID
			{
				get { return Environment.UserName.ToUpper(); }
			}
			// Authorization Rules
			public virtual void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
			{
				// Needs to be overriden to add new authorization rules
			}
			// Instance Authorization Rules
			public virtual void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
			{
				// Needs to be overriden to add new authorization rules
			}
			// Validation Rules
			public virtual void AddValidationRules(Csla.Validation.ValidationRules rules)
			{
				// Needs to be overriden to add new validation rules
			}
			// InstanceValidation Rules
			public virtual void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
			{
				// Needs to be overriden to add new validation rules
			}
		}
		#endregion
	} // Class
	#region Converter
	internal class ContentConverter : ExpandableObjectConverter
	{
		public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destType)
		{
			if (destType == typeof(string) && value is Content)
			{
				// Return the ToString value
				return ((Content)value).ToString();
			}
			return base.ConvertTo(context, culture, value, destType);
		}
	}
	#endregion
} // Namespace
//// The following is a sample Extension File.  You can use it to create ContentExt.cs
//using System;
//using System.Collections.Generic;
//using System.Text;
//using Csla;
//namespace VEPROMS.CSLA.Library
//{
//  public partial class Content
//  {
//    partial class ContentExtension : extensionBase
//    {
//      // TODO: Override automatic defaults
//      public virtual DateTime DefaultDTS
//      {
//        get { return DateTime.Now; }
//      }
//      public virtual string DefaultUserID
//      {
//        get { return Environment.UserName.ToUpper(); }
//      }
//      public new void AddAuthorizationRules(Csla.Security.AuthorizationRules rules)
//      {
//        //rules.AllowRead(Dbid, "");
//      }
//      public new void AddInstanceAuthorizationRules(Csla.Security.AuthorizationRules rules)
//      {
//        //rules.AllowInstanceRead(Dbid, "");
//      }
//      public new void AddValidationRules(Csla.Validation.ValidationRules rules)
//      {
//        rules.AddRule(
//          Csla.Validation.CommonRules.StringMaxLength,
//          new Csla.Validation.CommonRules.MaxLengthRuleArgs("Name", 100));
//      }
//      public new void AddInstanceValidationRules(Csla.Validation.ValidationRules rules)
//      {
//        rules.AddInstanceRule(/* Instance Validation Rule */);
//      }
//    }
//  }
//}