<%	string rootNamespaceToUse = _executingGenerator.RootNamespaceToUse;
	SDE_GeneralUtils.InitializeDropdownEntites(_executingGenerator);
	SDE_GeneralUtils.InitializeStateEntities(_executingGenerator);

	Project currentProject = _executingGenerator.ProjectDefinition;
	var entities =	_executingGenerator.Entities;
	var tpls = _executingGenerator.TypedLists;
	var tpvs = _executingGenerator.TypedViews;

	string errorMsg = string.Empty;

	string securityErrors = SDE_GeneralUtils.ValidateSecuritySettings(_executingGenerator);
	if (!string.IsNullOrEmpty(securityErrors))
		errorMsg += string.Format("Project Security settings has errors:\r\n{0}", securityErrors);
	
	foreach (EntityDefinition entity in entities)
	{
		// Validate the entity's DescriptiveField setting
		string entityErrors = SDE_GeneralUtils.ValidateEntitySettings(entity, _executingGenerator);
		if (!string.IsNullOrEmpty(entityErrors))
			errorMsg += string.Format("{0} settings has errors:\r\n{1}", entity.Name, entityErrors);
	}
	foreach (TypedListDefinition tpl in tpls)
	{
		// Validate the entity's DescriptiveField setting
		string tplErrors = SDE_GeneralUtils.ValidateTypedListSettings(tpl, currentProject);
		if (!string.IsNullOrEmpty(tplErrors))
			errorMsg += string.Format("{0} settings has errors:\r\n{1}", tpl.Name, tplErrors);
	}
	foreach (TypedViewDefinition tpv in tpvs)
	{
		// Validate the typedview's settings
		string tpvErrors = SDE_GeneralUtils.ValidateTypedViewSettings(tpv, _executingGenerator);
		if (!string.IsNullOrEmpty(tpvErrors))
			errorMsg += string.Format("{0} settings has errors:\r\n{1}", tpv.Name, tpvErrors);
	}
	if (!string.IsNullOrEmpty(errorMsg))
		throw new ArgumentException(errorMsg);

%>using SD.LLBLGen.Pro.ORMSupportClasses;

namespace <%=rootNamespaceToUse%>.ExtendedClasses
{
	public static class OrmExtension
	{
		public static void AddRange(this IRelationCollection originalRelations, IRelationCollection relationsToAdd)
		{
			foreach (IRelation r in relationsToAdd)
			{
				originalRelations.Add(r);
			}
		}

		public static RelationPredicateBucket MergeBuckets(RelationPredicateBucket bucket1, RelationPredicateBucket bucket2)
		{
			int null1 = (bucket1 == null) ? 0 : 1;
			int null2 = (bucket2 == null) ? 0 : 2;
			switch (null1 | null2)
			{
				case 1:
					return (RelationPredicateBucket)bucket1.Clone();
				case 2:
					return (RelationPredicateBucket)bucket2.Clone();
				case 3:
					RelationPredicateBucket toReturn = (RelationPredicateBucket)bucket1.Clone();
					toReturn.PredicateExpression.Add(bucket2.PredicateExpression);
					if (bucket2.Relations.Count > 0)
						toReturn.Relations.AddRange(bucket2.Relations);
					return toReturn;
				default:
					return new RelationPredicateBucket();
			}
		}
	}
}