Inheritance: nHydrate.Generator.Common.GeneratorFramework.BaseModelObject, ICodeFacadeObject, INamedObject
Ejemplo n.º 1
0
        public static IEnumerable<Column> GetValidSearchColumns(Table _currentTable)
        {
            try
            {
                var validColumns = new List<Column>();
                foreach (var column in _currentTable.GeneratedColumns)
                {
                    if (!(column.DataType == System.Data.SqlDbType.Binary ||
                        column.DataType == System.Data.SqlDbType.Image ||
                        column.DataType == System.Data.SqlDbType.NText ||
                        column.DataType == System.Data.SqlDbType.Text ||
                        column.DataType == System.Data.SqlDbType.Timestamp ||
                        column.DataType == System.Data.SqlDbType.Udt ||
                        column.DataType == System.Data.SqlDbType.VarBinary ||
                        column.DataType == System.Data.SqlDbType.Variant ||
                    column.DataType == System.Data.SqlDbType.Money))
                    {
                        validColumns.Add(column);
                    }
                }
                return validColumns.OrderBy(x => x.Name).AsEnumerable();

            }
            catch (Exception ex)
            {
                throw new Exception(_currentTable.DatabaseName + ": Failed on generation of select or template", ex);
            }
        }
		public TableExtendedPropertiesForm(Table table)
			: this()
		{
			_table = table;
			lblHeader.Text = table.Name + " Entity";

			var root = table.Root as ModelRoot;

			//Child tables
			foreach (var t in root.Database.Tables.OrderBy(x => x.Name))
			{
				if (t.IsInheritedFrom(table))
					lstChildTable.Items.Add(t.Name);
			}

			//Parent relationships
			foreach (Relation r in root.Database.Relations)
			{
				var parentTable = r.ParentTableRef.Object as Table;
				var childTable = r.ChildTableRef.Object as Table;
				if (childTable == table)
				{
					lstParentTable.Items.Add(parentTable.Name);
				}
			}

		}
Ejemplo n.º 3
0
            public static string GetBody(Table table, ModelRoot model)
            {
                try
                {
                    var allColumns = new List<Column>();
                    foreach (var column in table.GetColumnsFullHierarchy().Where(x => x.Generated).OrderBy(x => x.Name))
                    {
                        if (!(column.DataType == System.Data.SqlDbType.Binary ||
                            column.DataType == System.Data.SqlDbType.Image ||
                            column.DataType == System.Data.SqlDbType.NText ||
                            column.DataType == System.Data.SqlDbType.Text ||
                            column.DataType == System.Data.SqlDbType.Timestamp ||
                            column.DataType == System.Data.SqlDbType.Udt ||
                            column.DataType == System.Data.SqlDbType.VarBinary ||
                            column.DataType == System.Data.SqlDbType.Variant ||
                        column.DataType == System.Data.SqlDbType.Money))
                        {
                            allColumns.Add(column);
                        }
                    }

                    if (allColumns.Count != 0)
                    {
                        return BuildStoredProcedure(table, model, allColumns);
                    }

                    return "";

                }
                catch (Exception ex)
                {
                    throw new Exception(table.DatabaseName + ": Failed on generation of paging select statement", ex);
                }
            }
Ejemplo n.º 4
0
 public static string GetTableDatabaseName(ModelRoot model, Table table)
 {
     var retval = model.Database.TablePrefix;
     if (!string.IsNullOrEmpty(retval))
         return retval + "_" + table.DatabaseName;
     else
         return table.DatabaseName;
 }
Ejemplo n.º 5
0
        public SecurityFunction(INHydrateModelObject root, Table parent)
            : base(root)
        {
            _parent = parent;

            _parameters = new ReferenceCollection(this.Root, this, ReferenceType.Parameter);
            _parameters.ResetKey(Guid.Empty.ToString());
            _parameters.ObjectPlural = "Parameters";
            _parameters.ObjectSingular = "Parameter";
            _parameters.ImageIndex = ImageHelper.GetImageIndex(TreeIconConstants.FolderClose);
            _parameters.SelectedImageIndex = ImageHelper.GetImageIndex(TreeIconConstants.FolderOpen);
        }
Ejemplo n.º 6
0
		public TableComponent(INHydrateModelObject root, Table parent)
			: base(root)
		{
			_parent = parent;
			_columns = new ReferenceCollection(this.Root, this, ReferenceType.Column);

			_columns.ObjectPlural = "Fields";
			_columns.ObjectSingular = "Field";
			_columns.ImageIndex = ImageHelper.GetImageIndex(TreeIconConstants.FolderClose);
			_columns.SelectedImageIndex = ImageHelper.GetImageIndex(TreeIconConstants.FolderOpen);

		}
Ejemplo n.º 7
0
        public static string GetSQLCreateTable(ModelRoot model, Table table)
        {
            try
            {
                if (table.TypedTable == TypedTableConstants.EnumOnly)
                    return string.Empty;

                var sb = new StringBuilder();
                var tableName = Globals.GetTableDatabaseName(model, table);

                sb.AppendLine("--CREATE TABLE [" + table.DatabaseName + "]");
                sb.AppendLine("if not exists(select * from sysobjects where name = '" + tableName + "' and xtype = 'U')");
                sb.AppendLine("CREATE TABLE [" + table.GetSQLSchema() + "].[" + tableName + "] (");

                var firstLoop = true;
                foreach (var column in table.GeneratedColumns.OrderBy(x => x.SortOrder))
                {
                    if (!firstLoop) sb.AppendLine(",");
                    else firstLoop = false;
                    sb.Append("\t" + AppendColumnDefinition(column, allowDefault: true, allowIdentity: true));
                }
                AppendModifiedAudit(model, table, sb);
                AppendCreateAudit(model, table, sb);
                AppendTimestamp(model, table, sb);
                AppendTenantField(model, table, sb);

                //Emit PK
                var tableIndex = table.TableIndexList.FirstOrDefault(x => x.PrimaryKey);
                if (tableIndex != null)
                {
                    var indexName = "PK_" + table.DatabaseName.ToUpper();
                    sb.AppendLine(",");
                    sb.AppendLine("\t" + "CONSTRAINT [" + indexName + "] PRIMARY KEY " + (tableIndex.Clustered ? "CLUSTERED" : "NONCLUSTERED"));
                    sb.AppendLine("\t" + "(");
                    sb.AppendLine("\t\t" + Globals.GetSQLIndexField(table, tableIndex));
                    sb.AppendLine("\t" + ")");
                }
                else
                    sb.AppendLine();

                sb.AppendLine(")");
                return sb.ToString();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Ejemplo n.º 8
0
		public RelationCollectionForm(Table parentTable, ReferenceCollection referenceCollection)
			: this()
		{
			_referenceCollection = referenceCollection;
			_originalReferenceCollection = new ReferenceCollection(parentTable.Root, parentTable, ReferenceType.Relation);
			_originalReferenceCollection.AddRange((ICollection)referenceCollection);
			_parentTable = parentTable;

			lvwMembers.Columns.Clear();
			lvwMembers.Columns.Add(new ColumnHeader() { Text = "Parent", Width = 200 });
			lvwMembers.Columns.Add(new ColumnHeader() { Text = "Child", Width = 200 });
			lvwMembers.Columns.Add(new ColumnHeader() { Text = "Role", Width = 200 });

			lvwMembers.ListViewItemSorter = new nHydrate.Generator.Common.Forms.CommonLibrary.ListViewItemComparer(0, lvwMembers.Sorting);
			lvwMembers.Sort();

			this.LoadList();
		}
        private void AppendFullTemplate(StringBuilder sb, Table table, ModelRoot model)
        {
            try
            {
                var moduleSuffix = string.Empty;
                if (!string.IsNullOrEmpty(_model.ModuleName))
                    moduleSuffix = _model.ModuleName + "_";

                sb.AppendLine("if exists(select * from sys.objects where name = '" + GetStoredProcedureName(table, model, moduleSuffix) + "' and type = 'P' and type_desc = 'SQL_STORED_PROCEDURE')");
                sb.AppendLine("	drop procedure [" + table.GetSQLSchema() + "].[" + GetStoredProcedureName(table, model, moduleSuffix) + "]");
                sb.AppendLine("GO");
                sb.AppendLine();

                //Just drop the procedure if no CRUD SP
                if (!_model.Database.UseGeneratedCRUD)
                    return;

                sb.AppendLine("CREATE PROCEDURE [" + table.GetSQLSchema() + "].[" + GetStoredProcedureName(table, model, moduleSuffix) + "]");
                sb.AppendLine("(");
                sb.AppendLine(BuildParameterList(table, model));
                sb.AppendLine(")");
                sb.AppendLine("AS");
                sb.AppendLine("SET NOCOUNT OFF;");
                sb.AppendLine();
                sb.Append(SQLGeneratedBodyHelper.SQLInsertBusinessObjectBody(table, model));
                sb.AppendLine("GO");
                sb.AppendLine();
                if (model.Database.GrantExecUser != string.Empty)
                {
                    sb.AppendFormat("GRANT EXECUTE ON [" + table.GetSQLSchema() + "].[{0}] TO [{1}]", GetStoredProcedureName(table, model, moduleSuffix), model.Database.GrantExecUser).AppendLine();
                    sb.AppendLine("GO");
                    sb.AppendLine();
                }

            }
            catch (Exception ex)
            {
                throw;
            }

        }
Ejemplo n.º 10
0
 public static string GetSQLIndexField(Table table, TableIndex tableIndex)
 {
     try
     {
         var sb = new StringBuilder();
         var index = 0;
         foreach (var indexColumn in tableIndex.IndexColumnList)
         {
             var column = table.GeneratedColumns.FirstOrDefault(x => new Guid(x.Key) == indexColumn.FieldID);
             sb.Append("[" + column.DatabaseName + "]");
             if (index < tableIndex.IndexColumnList.Count - 1)
                 sb.Append(",");
             index++;
         }
         return sb.ToString();
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Ejemplo n.º 11
0
 public string GetDataSort(Table table)
 {
     try
     {
         var name = string.Empty;
         var description = string.Empty;
         foreach (CellEntry cellEntry in this.CellEntries)
         {
             var column = cellEntry.ColumnRef.Object as Column;
             if (column != null && column.IsIntegerType)
             {
                 if (column.Name.ToLower().Contains("order") || column.Name.ToLower().Contains("sort"))
                     return cellEntry.Value;
             }
         }
         return null;
     }
     catch (Exception ex)
     {
         throw;
     }
 }
Ejemplo n.º 12
0
		public RowEntryCollectionForm(Table table)
			: this()
		{
			_table = table;

			this.dataGridView1.Columns.Clear();

			//Setup Columns
			var dt = table.CreateDataTable();
			var columnCount = dt.Columns.Count;

			//Add Data
			foreach (RowEntry rowEntry in table.StaticData)
			{
				//Create a row
				var dr = dt.NewRow();
				dt.Rows.Add(dr);

				//Loop through the items and create datarows
				var count = System.Math.Min(rowEntry.CellEntries.Count, columnCount);
				for (var ii = 0; ii < count; ii++)
				{
					var cellEntry = rowEntry.CellEntries[ii];
					var staticColumn = cellEntry.ColumnRef.Object as Column;
					if ((staticColumn != null) && dt.Columns.Contains(staticColumn.Name))
					{
						dr[staticColumn.Name] = cellEntry.Value;
						//_loadedColumnList.Add(cellEntry.ColumnRef.Object as Column);
					}
				}
			}

			//Bind the grid
			this.dataGridView1.DataSource = dt;

		}
		public AuditEntityGeneratedTemplate(ModelRoot model, Table currentTable)
			: base(model)
		{
			_item = currentTable;
		}
 public SQLUpdateBusinessObjectTemplate(ModelRoot model, Table currentTable)
 {
     _model = model;
     _currentTable = currentTable;
 }
Ejemplo n.º 15
0
 public EntityExtenderTemplate(ModelRoot model, Table table)
     : base(model)
 {
     _currentTable = table;
 }
Ejemplo n.º 16
0
		private void AppendDeleteMap(Table currentTable, string moduleSuffix)
		{
			sb.AppendFormat("					<DeleteFunction FunctionName=\"{0}.Store." + _model.GetStoredProcedurePrefix() + "_{1}_{2}Delete\">", this.GetLocalNamespace(), currentTable.PascalName, moduleSuffix).AppendLine();
			foreach (var currentColumn in currentTable.PrimaryKeyColumns.OrderBy(x => x.Name))
			{
				sb.AppendFormat("						<ScalarProperty Name=\"{0}\" ParameterName=\"Original_{1}\" />",
					currentColumn.PascalName,
					currentColumn.DatabaseName).AppendLine();
			}

			//Now all of the associations
			foreach (var currentRelation in currentTable.ChildRoleRelationsFullHierarchy)
			{
				var parentTable = (Table)currentRelation.ParentTableRef.Object;
				var childTable = (Table)currentRelation.ChildTableRef.Object;

				if (childTable.Generated && parentTable.Generated)
				{
					foreach (ColumnRelationship columnRelationship in currentRelation.ColumnRelationships)
					{
						var parentColumn = (Column)columnRelationship.ParentColumnRef.Object;
						var childColumn = (Column)columnRelationship.ChildColumnRef.Object;
						//if (!childColumn.PrimaryKey)
						//{
						//var typeTable = _relatedTypeTableCache[childColumn];
						//if (typeTable != null)
						//{
						//  sb.AppendLine("						<ComplexProperty Name=\"" + typeTable.PascalName + "\" TypeName=\"" + this.GetLocalNamespace() + ".Entity." + typeTable.PascalName + "Wrapper\">");
						//  sb.AppendLine("							<ScalarProperty Name=\"Value\" ParameterName=\"" + parentTable.DatabaseName + "_" + parentColumn.DatabaseName + "\" />");
						//  sb.AppendLine("						</ComplexProperty>");
						//}
						//else
						{
							sb.AppendFormat("						<ScalarProperty Name=\"{0}\" ParameterName=\"{1}\" />",
								childColumn.PascalName,
								currentRelation.DatabaseRoleName + parentTable.DatabaseName + "_" + parentColumn.DatabaseName).AppendLine();
						}
						//}
					}
				}
			}

			sb.AppendFormat("					</DeleteFunction>").AppendLine();
		}
Ejemplo n.º 17
0
		private void AppendUpdateMapScalarProperties(Table currentTable)
		{
			try
			{
				if (currentTable.AllowTimestamp)
				{
					sb.AppendFormat("						<ScalarProperty Name=\"{0}\" ParameterName=\"Original_{1}\" Version=\"Original\" />", _model.Database.TimestampPascalName, _model.Database.TimestampDatabaseName);
					sb.AppendLine();
				}

				foreach (var currentColumn in currentTable.PrimaryKeyColumns.OrderBy(x => x.Name))
				{
					sb.AppendFormat("						<ScalarProperty Name=\"{0}\" ParameterName=\"Original_{1}\" Version=\"Original\" />", currentColumn.PascalName, currentColumn.DatabaseName);
					sb.AppendLine();
				}

				var fkColumns = new Dictionary<string, Column>();
				foreach (var currentRelation in currentTable.ChildRoleRelations)
				{
					if (currentRelation.FkColumns.Count(x => x.PrimaryKey) == 0)
					{
						var parentTable = (Table)currentRelation.ParentTableRef.Object;
						var childTable = (Table)currentRelation.ChildTableRef.Object;
						if (childTable.Generated && parentTable.Generated)
						{
							//sb.AppendFormat("						<AssociationEnd AssociationSet=\"{0}\" From=\"{3}{1}List\" To=\"{3}{2}\">", currentRelation.GetCodeFkName(), childTable.PascalName, parentTable.PascalName, currentRelation.PascalRoleName).AppendLine();
							foreach (ColumnRelationship columnRelationship in currentRelation.ColumnRelationships)
							{
								var parentColumn = (Column)columnRelationship.ParentColumnRef.Object;
								var childColumn = (Column)columnRelationship.ChildColumnRef.Object;

								//var typeTable = _relatedTypeTableCache[childColumn];
								//if (typeTable != null)
								//{
								//  sb.AppendLine("						<ComplexProperty Name=\"" + typeTable.PascalName + "\" TypeName=\"" + this.GetLocalNamespace() + ".Entity." + typeTable.PascalName + "Wrapper\">");
								//  sb.AppendLine("							<ScalarProperty Name=\"Value\" ParameterName=\"" + childColumn.DatabaseName + "\" Version=\"Current\" />");
								//  sb.AppendLine("						</ComplexProperty>");
								//}
								//else
								{
									sb.AppendFormat("						<ScalarProperty Name=\"{0}\" ParameterName=\"{1}\" Version=\"Current\" />", childColumn.PascalName, childColumn.DatabaseName);
									sb.AppendLine();
								}
								if (!fkColumns.ContainsKey(childColumn.Key))
									fkColumns.Add(childColumn.Key, childColumn);
							}
							//sb.AppendLine("						</AssociationEnd>");
						}
					}
				}

				//Get all columns for all inheritance
				foreach (var currentColumn in _fullHierarchyColumnCache[currentTable])
				{
					if (currentColumn.RelationshipRef == null &&
						!currentColumn.ComputedColumn &&
						!currentColumn.IsReadOnly &&
						!currentColumn.PrimaryKey &&
						!fkColumns.ContainsKey(currentColumn.Key))
					{
						//var typeTable = _relatedTypeTableCache[currentColumn];
						//if (typeTable != null)
						//{
						//  sb.AppendLine("						<ComplexProperty Name=\"" + typeTable.PascalName + "\" TypeName=\"" + this.GetLocalNamespace() + ".Entity." + typeTable.PascalName + "Wrapper\">");
						//  sb.AppendLine("							<ScalarProperty Name=\"Value\" ParameterName=\"" + currentColumn.DatabaseName + "\" Version=\"Current\" />");
						//  sb.AppendLine("						</ComplexProperty>");
						//}
						//else
						{
							sb.AppendFormat("						<ScalarProperty Name=\"{0}\" ParameterName=\"{1}\" Version=\"Current\" />", currentColumn.PascalName, currentColumn.DatabaseName);
							sb.AppendLine();
						}
					}
				}

				if (currentTable.AllowModifiedAudit)
				{
					sb.AppendFormat("						<ScalarProperty Name=\"{0}\" ParameterName=\"{1}\" Version=\"Current\" />", _model.Database.ModifiedByPascalName, _model.Database.ModifiedByDatabaseName);
					sb.AppendLine();
					sb.AppendFormat("						<ScalarProperty Name=\"{0}\" ParameterName=\"{1}\" Version=\"Current\" />", _model.Database.ModifiedDatePascalName, _model.Database.ModifiedDateDatabaseName);
					sb.AppendLine();
				}
			}
			catch (Exception ex)
			{
				throw;
			}
		}
 public SQLStoredProcedureTableAllTemplate(ModelRoot model, Table table, bool useSingleFile)
     : base(model)
 {
     _table = table;
     _useSingleFile = useSingleFile;
 }
Ejemplo n.º 19
0
        protected string BuildUpdateWhereStatement(Table table)
        {
            try
            {
                var IsTimeStamp = (table == _currentComponent.Parent.GetAbsoluteBaseTable()) && _currentComponent.Parent.AllowTimestamp;

                var output = new StringBuilder();
                var index = 0;
                foreach (var column in table.PrimaryKeyColumns.OrderBy(x => x.Name))
                {
                    output.Append("[" + table.GetSQLSchema() + "].");
                    output.Append("[" + table.DatabaseName + "].");
                    output.Append("[" + column.DatabaseName + "] = ");
                    output.Append("@Original_");
                    output.Append(column.ToDatabaseCodeIdentifier());
                    if (index < table.PrimaryKeyColumns.Count - 1 || IsTimeStamp)
                        output.Append(" AND" + Environment.NewLine + "\t");
                    index++;
                }

                if (IsTimeStamp)
                {
                    output.AppendFormat("[" + _currentComponent.Parent.GetAbsoluteBaseTable().GetSQLSchema() + "].[" + _currentComponent.Parent.GetAbsoluteBaseTable().DatabaseName + "].[{0}] = @Original_{0}", _model.Database.TimestampColumnName);
                }

                output.AppendLine();
                return output.ToString();
            }

            catch (Exception ex)
            {
                throw new Exception("BuildSetStatement failed: " + table.DatabaseName, ex);
            }
        }
Ejemplo n.º 20
0
		private void AppendInsertMapScalar(Table currentTable)
		{
			try
			{
				//Get all columns for all inheritance
				foreach (var currentColumn in _fullHierarchyColumnCache[currentTable])
				{
					if (currentColumn.RelationshipRef == null &&
						!currentColumn.ComputedColumn &&
						!currentColumn.IsReadOnly &&
						(!currentColumn.PrimaryKey || currentTable.GetBasePKColumn(currentColumn).Identity != IdentityTypeConstants.Database))
					{
						//var typeTable = _relatedTypeTableCache[currentColumn];
						//if (typeTable != null)
						//{
						//  sb.AppendLine("						<ComplexProperty Name=\"" + typeTable.PascalName + "\" TypeName=\"" + this.GetLocalNamespace() + ".Entity." + typeTable.PascalName + "Wrapper\">");
						//  sb.AppendLine("							<ScalarProperty Name=\"Value\" ParameterName=\"" + currentColumn.DatabaseName + "\" />");
						//  sb.AppendLine("						</ComplexProperty>");
						//}
						//else
						{
							sb.AppendFormat("						<ScalarProperty Name=\"{0}\" ParameterName=\"{1}\" />", currentColumn.PascalName, currentColumn.DatabaseName).AppendLine();
						}
					}
				}

				if (currentTable.AllowCreateAudit)
				{
					sb.AppendFormat("						<ScalarProperty Name=\"{0}\" ParameterName=\"{1}\" />", _model.Database.CreatedByPascalName, _model.Database.CreatedByDatabaseName).AppendLine();
					sb.AppendFormat("						<ScalarProperty Name=\"{0}\" ParameterName=\"{1}\" />", _model.Database.CreatedDatePascalName, _model.Database.CreatedDateDatabaseName).AppendLine();
				}

				if (currentTable.AllowModifiedAudit)
				{
					sb.AppendFormat("						<ScalarProperty Name=\"{0}\" ParameterName=\"{1}\" />", _model.Database.ModifiedByPascalName, _model.Database.ModifiedByDatabaseName).AppendLine();
				}

			}
			catch (Exception ex)
			{
				throw;
			}
		}
Ejemplo n.º 21
0
		private void AppendInsertReturnProperties(Table currentTable)
		{
			foreach (var currentColumn in _fullHierarchyColumnCache[currentTable])
			{
				if (currentColumn.PrimaryKey && currentTable.GetBasePKColumn(currentColumn).Identity != IdentityTypeConstants.Database)
				{
					//Do Nothing
				}
				else if (!currentColumn.IsForeignKeyIgnoreInheritance())
				{
					sb.AppendFormat("						<ResultBinding Name=\"{0}\" ColumnName=\"{1}\" />", currentColumn.PascalName, currentColumn.DatabaseName).AppendLine();
				}
			}

			if (currentTable.AllowCreateAudit)
			{
				sb.AppendFormat("						<ResultBinding Name=\"{0}\" ColumnName=\"{1}\" />", _model.Database.CreatedByPascalName, _model.Database.CreatedByDatabaseName).AppendLine();
				sb.AppendFormat("						<ResultBinding Name=\"{0}\" ColumnName=\"{1}\" />", _model.Database.CreatedDatePascalName, _model.Database.CreatedDateDatabaseName).AppendLine();
			}

			if (currentTable.AllowModifiedAudit)
			{
				sb.AppendFormat("						<ResultBinding Name=\"{0}\" ColumnName=\"{1}\" />", _model.Database.ModifiedByPascalName, _model.Database.ModifiedByDatabaseName).AppendLine();
				sb.AppendFormat("						<ResultBinding Name=\"{0}\" ColumnName=\"{1}\" />", _model.Database.ModifiedDatePascalName, _model.Database.ModifiedDateDatabaseName).AppendLine();
			}

			if (currentTable.AllowTimestamp)
			{
				sb.AppendFormat("						<ResultBinding Name=\"{0}\" ColumnName=\"{1}\" />", _model.Database.TimestampPascalName, _model.Database.TimestampDatabaseName).AppendLine();
			}
		}
Ejemplo n.º 22
0
		private void AppendInsertMap(Table currentTable, string moduleSuffix)
		{
			sb.AppendFormat("					<InsertFunction FunctionName=\"{0}.Store." + _model.GetStoredProcedurePrefix() + "_{1}_{2}Insert\">", this.GetLocalNamespace(), currentTable.PascalName, moduleSuffix).AppendLine();
			AppendInsertMapScalar(currentTable);
			AppendInsertReturnProperties(currentTable);
			sb.AppendLine("					</InsertFunction>");
		}
Ejemplo n.º 23
0
		private void AppendMappingFragment(Table table)
		{
			if (table.IsTenant)
			{
				sb.AppendFormat("				<MappingFragment StoreEntitySet=\"{0}\">", _model.TenantPrefix + "_" + table.DatabaseName);
			}
			else
			{
				sb.AppendFormat("				<MappingFragment StoreEntitySet=\"{0}\">", table.DatabaseName);
			}

			sb.AppendLine();
			foreach (var currentColumn in table.GetColumns().Where(x => x.Generated).OrderBy(x => x.Name))
			{
				//var typeTable = _relatedTypeTableCache[currentColumn];
				//if (typeTable != null)
				//{
				//  sb.AppendLine("					<ComplexProperty Name=\"" + typeTable.PascalName + "\" TypeName=\"" + this.GetLocalNamespace() + ".Entity." + typeTable.PascalName + "Wrapper\">");
				//  sb.AppendLine("						<ScalarProperty Name=\"Value\" ColumnName=\"" + currentColumn.DatabaseName + "\" />");
				//  sb.AppendLine("					</ComplexProperty>");
				//}
				//else
				{
					sb.AppendFormat("					<ScalarProperty Name=\"{0}\" ColumnName=\"{1}\" />", currentColumn.PascalName, currentColumn.DatabaseName).AppendLine();
				}
			}

			//No auditing for Associative table
			if (!table.AssociativeTable)
			{
				if (table.AllowCreateAudit)
				{
					sb.AppendFormat("					<ScalarProperty Name=\"{0}\" ColumnName=\"{1}\" />", _model.Database.CreatedByPascalName, _model.Database.CreatedByDatabaseName).AppendLine();
					sb.AppendFormat("					<ScalarProperty Name=\"{0}\" ColumnName=\"{1}\" />", _model.Database.CreatedDatePascalName, _model.Database.CreatedDateDatabaseName).AppendLine();
				}

				if (table.AllowModifiedAudit)
				{
					sb.AppendFormat("					<ScalarProperty Name=\"{0}\" ColumnName=\"{1}\" />", _model.Database.ModifiedByPascalName, _model.Database.ModifiedByDatabaseName).AppendLine();
					sb.AppendFormat("					<ScalarProperty Name=\"{0}\" ColumnName=\"{1}\" />", _model.Database.ModifiedDatePascalName, _model.Database.ModifiedDateDatabaseName).AppendLine();
				}

				//For Descendents with NO generated CRUD layer do NOT add timestamp column as concurrency is handled by the ancestor with EF
				if (table.AllowTimestamp)
				{
					if (!_model.Database.UseGeneratedCRUD && table.ParentTable != null)
					{
						//Do Nothing
					}
					else
					{
						sb.AppendFormat("					<ScalarProperty Name=\"{0}\" ColumnName=\"{1}\" />", _model.Database.TimestampPascalName, _model.Database.TimestampDatabaseName).AppendLine();
					}
				}
			}

			sb.AppendFormat("				</MappingFragment>").AppendLine();
		}
Ejemplo n.º 24
0
 public ReadOnlyCollection <Relation> FindByChildTable(Table table)
 {
     return(FindByChildTable(table, false));
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Determines if the specified table is an ancestor of the this table object
 /// </summary>
 /// <param name="table"></param>
 /// <returns></returns>
 public bool IsInheritedFrom(Table table)
 {
     var t = this.ParentTable;
     while (t != null)
     {
         if (t == table) return true;
         t = t.ParentTable;
     }
     return false;
 }
Ejemplo n.º 26
0
 /// <summary>
 /// Determines if the specified table can be a parent of this table
 /// </summary>
 /// <param name="parentTable"></param>
 /// <returns></returns>
 public virtual bool CanInherit(Table parentTable)
 {
     //Ensure that there are no circles
     var tList = parentTable.GetTableHierarchy();
     return !tList.Contains(this);
 }
Ejemplo n.º 27
0
		public override void Initialize(IComponent component)
		{
			base.Initialize (component);
			_table = (Table)component;
		}
Ejemplo n.º 28
0
        protected string BuildSetStatement(Table table)
        {
            try
            {
                var validColumns = new List<Column>();
                foreach (Reference reference in _currentComponent.Columns)
                {
                    validColumns.Add((Column)reference.Object);
                }

                //Get Column List
                var columnList = new List<Column>();
                foreach (var column in table.GeneratedColumns.Where(x => !x.ComputedColumn && !x.IsReadOnly))
                {
                    if (validColumns.Contains(column))
                    {
                        if (!column.PrimaryKey && (column.Identity != IdentityTypeConstants.Database))
                            columnList.Add(column);
                    }
                }

                var index = 0;
                var output = new StringBuilder();
                foreach (var column in columnList)
                {
                    output.Append("\t[" + column.DatabaseName + "] = @" + column.ToDatabaseCodeIdentifier());
                    if (index < columnList.Count - 1 || table.AllowModifiedAudit)
                        output.Append(",");
                    output.AppendLine();
                    index++;
                }

                if (table.AllowModifiedAudit)
                {
                    output.AppendLine("\t[" + _model.Database.ModifiedByColumnName + "] = @" + _model.Database.ModifiedByColumnName + ",");
                    output.AppendLine("\t[" + _model.Database.ModifiedDateColumnName + "] = @" + _model.Database.ModifiedDateColumnName);
                }

                return output.ToString();
            }
            catch (Exception ex)
            {
                throw new Exception("BuildSetStatement failed: " + table.DatabaseName, ex);
            }
        }
Ejemplo n.º 29
0
		private void AppendUpdateMap(Table currentTable, string moduleSuffix)
		{
			var spName = string.Format("{0}.Store." + _model.GetStoredProcedurePrefix() + "_{1}_{2}Update", this.GetLocalNamespace(), currentTable.PascalName, moduleSuffix);
			if (currentTable.AssociativeTable) spName = string.Format("{0}.Store." + _model.GetStoredProcedurePrefix() + "_NOOP", this.GetLocalNamespace(), currentTable.PascalName);
			sb.AppendLine("					<UpdateFunction FunctionName=\"" + spName + "\">");
			if (!currentTable.AssociativeTable)
			{
				AppendUpdateMapScalarProperties(currentTable);
				AppendUpdateMapReturnProperties(currentTable);
			}
			sb.AppendFormat("					</UpdateFunction>").AppendLine();
		}
Ejemplo n.º 30
0
        /// <summary>
        /// Determines if this table shares a common ancestor with the specified table
        /// </summary>
        /// <param name="table"></param>
        /// <returns></returns>
        public bool ShareAncestor(Table table)
        {
            if (table == null) return false;
            if (table == this) return false;

            var list1 = this.GetTableHierarchy();
            var list2 = table.GetTableHierarchy();
            return (list1.Intersect(list2).Count() > 0);
        }
Ejemplo n.º 31
0
		private void AppendUpdateMapReturnProperties(Table currentTable)
		{
			foreach (var currentColumn in _fullHierarchyColumnCache[currentTable])
			{
				if (!currentColumn.PrimaryKey && !currentColumn.IsForeignKey())
				{
					sb.AppendFormat("						<ResultBinding Name=\"{0}\" ColumnName=\"{1}\" />", currentColumn.PascalName, currentColumn.DatabaseName);
					sb.AppendLine();
				}
			}

			if (currentTable.AllowCreateAudit)
			{
				sb.AppendFormat("						<ResultBinding Name=\"{0}\" ColumnName=\"{1}\" />", _model.Database.CreatedByPascalName, _model.Database.CreatedByDatabaseName);
				sb.AppendLine();
				sb.AppendFormat("						<ResultBinding Name=\"{0}\" ColumnName=\"{1}\" />", _model.Database.CreatedDatePascalName, _model.Database.CreatedDateDatabaseName);
				sb.AppendLine();
			}

			if (currentTable.AllowModifiedAudit)
			{
				sb.AppendFormat("						<ResultBinding Name=\"{0}\" ColumnName=\"{1}\" />", _model.Database.ModifiedByPascalName, _model.Database.ModifiedByDatabaseName);
				sb.AppendLine();
				sb.AppendFormat("						<ResultBinding Name=\"{0}\" ColumnName=\"{1}\" />", _model.Database.ModifiedDatePascalName, _model.Database.ModifiedDateDatabaseName);
				sb.AppendLine();
			}

			if (currentTable.AllowTimestamp)
			{
				sb.AppendFormat("						<ResultBinding Name=\"{0}\" ColumnName=\"{1}\" />", _model.Database.TimestampPascalName, _model.Database.TimestampDatabaseName);
				sb.AppendLine();
			}

		}