GetTableHierarchy() public method

Get the full hierarchy of tables starting with this table and working back to the most base table
public GetTableHierarchy ( ) : IEnumerable
return IEnumerable
        private void ReloadControl()
        {
            if (ControllerListView != null)
            {
                ControllerListView.BeginUpdate();
            }

            try
            {
                var   referenceCollection = (ReferenceCollection)this.Object;
                Table parentTable         = null;
                if (referenceCollection.Parent is Table)
                {
                    parentTable = (Table)referenceCollection.Parent;
                }

                //Load the list
                var shallowColumnNames = new List <string>();
                ControllerListView.Items.Clear();
                foreach (Reference reference in referenceCollection)
                {
                    var column = ((Column)reference.Object);
                    shallowColumnNames.Add(column.Name.ToLower());
                    this.AddColumnNode(reference, column);
                }

                //Load the inherited columns
                if (parentTable != null)
                {
                    var allTables = new List <Table>(parentTable.GetTableHierarchy());
                    allTables.Remove(parentTable);

                    //Loop through all base tables and list columns that are NOT included in this table (the PK/audit columns)
                    foreach (var table in allTables)
                    {
                        foreach (var column in table.GeneratedColumns)
                        {
                            if (!shallowColumnNames.Contains(column.Name.ToLower()))
                            {
                                shallowColumnNames.Add(column.Name.ToLower());                                 //just in case, no duplicates
                                this.AddColumnNode(column);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (ControllerListView != null)
                {
                    ControllerListView.EndUpdate();
                }
            }
        }
示例#2
0
        /// <summary>
        /// Find all relationships that have a specific child table
        /// </summary>
        /// <param name="table">The table from which all relations begin</param>
        /// <param name="includeHierarchy">Determines if the return includes all tables in the inheritence tree</param>
        /// <returns></returns>
        public ReadOnlyCollection <Relation> FindByChildTable(Table table, bool includeHierarchy)
        {
            try
            {
                var retval     = new List <Relation>();
                var tableList  = new List <Table>();
                var columnList = new List <Column>();
                if (includeHierarchy)
                {
                    tableList.AddRange(table.GetTableHierarchy());
                    foreach (var t in tableList)
                    {
                        foreach (var column in (from x in t.GetColumnsFullHierarchy(true) select x))
                        {
                            columnList.Add(column);
                        }
                    }
                }
                else
                {
                    tableList = new List <Table>();
                    tableList.Add(table);
                    columnList.AddRange(table.GetColumns());
                }

                foreach (Relation relation in this)
                {
                    var childTable = (Table)relation.ChildTableRef.Object;
                    foreach (ColumnRelationship columnRelationship in relation.ColumnRelationships)
                    {
                        foreach (var column in columnList)
                        {
                            if (tableList.Contains(childTable))
                            {
                                if (!retval.Contains(relation))
                                {
                                    retval.Add(relation);
                                }
                            }
                        }
                    }
                }

                return(retval.AsReadOnly());
            }
            catch (Exception ex)
            {
                throw;
            }
        }
示例#3
0
        /// <summary>
        /// Find all relationships that have a specific parent table
        /// </summary>
        /// <param name="table">The table from which all relations begin</param>
        /// <param name="includeHierarchy">Determines if the return includes all tables in the inheritence tree</param>
        /// <returns></returns>
        public ReadOnlyCollection <ViewRelation> FindByParentTable(Table table, bool includeHierarchy)
        {
            var tableList  = new List <Table>();
            var columnList = new List <Column>();

            if (includeHierarchy)
            {
                tableList.AddRange(new List <Table>(table.GetTableHierarchy()));
                foreach (var t in tableList)
                {
                    foreach (var column in (from x in t.GetColumnsFullHierarchy(true) select x))
                    {
                        columnList.Add(column);
                    }
                }
            }
            else
            {
                tableList = new List <Table>();
                tableList.Add(table);
                columnList.AddRange(table.GetColumns());
            }

            var retval = new List <ViewRelation>();

            foreach (ViewRelation relation in this)
            {
                var parentTable = (Table)relation.ParentTableRef.Object;
                foreach (ViewColumnRelationship columnRelationship in relation.ColumnRelationships)
                {
                    foreach (var column in columnList)
                    {
                        if (tableList.Contains(parentTable))
                        {
                            if (!retval.Contains(relation))
                            {
                                retval.Add(relation);
                            }
                        }
                    }
                }
            }

            return(retval.AsReadOnly());
        }
示例#4
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);
        }
示例#5
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);
 }
        private void AppendTableClass(Table table)
        {
            try
            {
                sb.AppendLine("	#region " + table.PascalName + "Query");
                sb.AppendLine();

                sb.AppendLine("	/// <summary>");
                sb.AppendLine("	/// This is a helper object for running LINQ queries on the " + table.PascalName + " collection.");
                sb.AppendLine("	/// </summary>");
                sb.AppendLine("	[Serializable]");
                if (table.IsTenant)
                    sb.AppendLine("	[Table(Name = \"" + _model.TenantPrefix + "_" + table.DatabaseName + "\")]");
                else
                    sb.AppendLine("	[Table(Name = \"" + table.DatabaseName + "\")]");
                sb.AppendLine("	[System.CodeDom.Compiler.GeneratedCode(\"nHydrateModelGenerator\", \"" + _model.ModelToolVersion + "\")]");
                sb.AppendLine("	public partial class " + table.PascalName + "Query : IBusinessObjectLINQQuery");
                sb.AppendLine("	{");

                sb.AppendLine("		#region Properties");
                var allTables = table.GetTableHierarchy();

                var columnList = table.GetColumnsFullHierarchy().Where(x => x.Generated).ToList();
                foreach (var c in columnList.OrderBy(x => x.Name))
                {
                    var description = c.Description.Trim();
                    if (!string.IsNullOrEmpty(description)) description += "\r\n";
                    description += "(Maps to the '" + table.DatabaseName + "." + c.DatabaseName + "' database field)";

                    sb.AppendLine("		/// <summary>");
                    StringHelper.LineBreakCode(sb, description, "		/// ");
                    sb.AppendLine("		/// </summary>");
                    sb.Append("		[Column(");
                    sb.Append("Name = \"" + c.DatabaseName + "\", ");
                    sb.Append("DbType = \"" + c.DatabaseTypeRaw + "\", ");
                    sb.Append("CanBeNull = " + c.AllowNull.ToString().ToLower() + ", ");
                    sb.Append("IsPrimaryKey = " + table.PrimaryKeyColumns.Contains(c).ToString().ToLower());
                    sb.AppendLine(")]");
                    sb.AppendLine("		[System.Diagnostics.DebuggerNonUserCode()]");
                    sb.AppendLine("		public virtual " + c.GetCodeType(true) + " " + c.PascalName + " { get; set; }");
                }

                if (table.AllowCreateAudit)
                {
                    sb.AppendLine("		/// <summary>");
                    sb.AppendLine("		/// The date of creation");
                    sb.AppendLine("		/// </summary>");
                    sb.AppendLine("		[Column(Name = \"" + _model.Database.CreatedDateColumnName + "\", DbType = \"DateTime\", CanBeNull = true)]");
                    sb.AppendLine("		[System.Diagnostics.DebuggerNonUserCode()]");
                    sb.AppendLine("		public virtual DateTime? " + _model.Database.CreatedDatePascalName + " { get; set; }");

                    sb.AppendLine("		/// <summary>");
                    sb.AppendLine("		/// The name of the creating entity");
                    sb.AppendLine("		/// </summary>");
                    sb.AppendLine("		[Column(Name = \"" + _model.Database.CreatedByColumnName + "\", DbType = \"VarChar(100)\", CanBeNull = true)]");
                    sb.AppendLine("		[System.Diagnostics.DebuggerNonUserCode()]");
                    sb.AppendLine("		public virtual string " + _model.Database.CreatedByPascalName + " { get; set; }");
                }

                if (table.AllowModifiedAudit)
                {
                    sb.AppendLine("		/// <summary>");
                    sb.AppendLine("		/// The date of last modification");
                    sb.AppendLine("		/// </summary>");
                    sb.AppendLine("		[Column(Name = \"" + _model.Database.ModifiedDateColumnName + "\", DbType = \"DateTime\", CanBeNull = true)]");
                    sb.AppendLine("		public virtual DateTime? " + _model.Database.ModifiedDatePascalName + " { get; set; }");

                    sb.AppendLine("		/// <summary>");
                    sb.AppendLine("		/// The name of the last modifing entity");
                    sb.AppendLine("		/// </summary>");
                    sb.AppendLine("		[Column(Name = \"" + _model.Database.ModifiedByColumnName + "\", DbType = \"VarChar(100)\", CanBeNull = true)]");
                    sb.AppendLine("		[System.Diagnostics.DebuggerNonUserCode()]");
                    sb.AppendLine("		public virtual string " + _model.Database.ModifiedByPascalName + " { get; set; }");
                }

                if (table.AllowTimestamp)
                {
                    sb.AppendLine("		/// <summary>");
                    sb.AppendLine("		/// This is an internal field and is not to be used.");
                    sb.AppendLine("		/// </summary>");
                    sb.AppendLine("		[Column(Name = \"" + _model.Database.TimestampColumnName + "\", DbType = \"Binary\", CanBeNull = false)]");
                    sb.AppendLine("		[System.Diagnostics.DebuggerNonUserCode()]");
                    sb.AppendLine("		public virtual byte[] " + _model.Database.TimestampPascalName + " { get; set; }");
                }

                ////Add child relationships
                //foreach (var relation in _model.Database.Relations.FindByParentTable(table, true).Where(x => x.IsGenerated))
                //{
                //    //Relation relation = (Relation)reference.Object;
                //    var parentTable = (Table)relation.ParentTableRef.Object;
                //    var childTable = (Table)relation.ChildTableRef.Object;
                //    //Column pkColumn = (Column)relation.ColumnRelationships[0].ChildColumnRef.Object;

                //    var thisKey = string.Empty;
                //    var otherKey = string.Empty;
                //    foreach (var columnRelationship in relation.ColumnRelationships.AsEnumerable())
                //    {
                //        thisKey += ((Column)columnRelationship.ParentColumnRef.Object).PascalName + ",";
                //        otherKey += ((Column)columnRelationship.ChildColumnRef.Object).PascalName + ",";
                //    }
                //    if (!string.IsNullOrEmpty(thisKey)) thisKey = thisKey.Substring(0, thisKey.Length - 1);
                //    if (!string.IsNullOrEmpty(otherKey)) otherKey = otherKey.Substring(0, otherKey.Length - 1);

                //    if (childTable.Generated & (childTable.TypedTable != TypedTableConstants.EnumOnly) && (!allTables.Contains(childTable)))
                //    {
                //        sb.AppendLine("		/// <summary>");
                //        sb.AppendLine("		/// This is a mapping of the relationship with the " + childTable.PascalName + " entity." + (relation.PascalRoleName == "" ? "" : " (Role: '" + relation.RoleName + "')"));
                //        sb.AppendLine("		/// </summary>");
                //        sb.AppendLine("		[Association(ThisKey = \"" + thisKey + "\", OtherKey = \"" + otherKey + "\")]");
                //        if (relation.IsOneToOne)
                //            sb.AppendLine("		public " + this.GetLocalNamespace() + "." + childTable.PascalName + "Query " + relation.PascalRoleName + childTable.PascalName + " { get; private set; }");
                //        else
                //            sb.AppendLine("		public " + this.GetLocalNamespace() + "." + childTable.PascalName + "Query " + relation.PascalRoleName + childTable.PascalName + "List { get; private set; }");
                //        sb.AppendLine();
                //    }

                //}

                //Add parent relationships
                foreach (var relation in _model.Database.Relations.FindByChildTable(table, true).Where(x => x.IsGenerated))
                {
                    var parentTable = (Table)relation.ParentTableRef.Object;
                    var childTable = (Table)relation.ChildTableRef.Object;

                    //Do not process self-referencing relationships
                    if (parentTable != table)
                    {
                        var thisKey = string.Empty;
                        var otherKey = string.Empty;
                        foreach (ColumnRelationship columnRelationship in relation.ColumnRelationships)
                        {
                            thisKey += ((Column)columnRelationship.ChildColumnRef.Object).PascalName + ",";
                            otherKey += ((Column)columnRelationship.ParentColumnRef.Object).PascalName + ",";
                        }
                        if (!string.IsNullOrEmpty(thisKey)) thisKey = thisKey.Substring(0, thisKey.Length - 1);
                        if (!string.IsNullOrEmpty(otherKey)) otherKey = otherKey.Substring(0, otherKey.Length - 1);

                        if (parentTable.Generated && (parentTable.TypedTable != TypedTableConstants.EnumOnly) && (!allTables.Contains(parentTable)))
                        {
                            sb.AppendLine("		/// <summary>");
                            sb.AppendLine("		/// This is a mapping of the relationship with the " + parentTable.PascalName + " entity." + (relation.PascalRoleName == "" ? "" : " (Role: '" + relation.RoleName + "')"));
                            sb.AppendLine("		/// </summary>");
                            sb.AppendLine("		[Association(ThisKey = \"" + thisKey + "\", OtherKey = \"" + otherKey + "\")]");
                            sb.AppendLine("		public " + this.GetLocalNamespace() + "." + parentTable.PascalName + "Query " + relation.PascalRoleName + parentTable.PascalName + " { get; private set; }");
                            sb.AppendLine();
                        }

                    }
                }

                sb.AppendLine();
                sb.AppendLine("		#endregion");
                sb.AppendLine();
                sb.AppendLine("	}");
                sb.AppendLine();

                sb.AppendLine("	#endregion");
                sb.AppendLine();

            }
            catch (Exception ex)
            {
                throw;
            }
        }
            public static string GetBody(Table table, ModelRoot model)
            {
                var sb = new StringBuilder();

                if (table.AllowModifiedAudit)
                {
                    sb.AppendLine("IF (@" + model.Database.ModifiedDateColumnName + " IS NULL)");
                    sb.AppendLine("SET @" + model.Database.ModifiedDateColumnName + " = " + model.GetSQLDefaultDate() + ";");
                    sb.AppendLine();
                }

                sb.AppendLine("SET NOCOUNT ON;");

                if (!table.Immutable)
                {
                    var tableList = table.GetTableHierarchy();
                    foreach (var t in tableList)
                    {
                        //If there is nothing to set then do not do anything
                        var setStatment = BuildSetStatement(t, model);
                        if (!string.IsNullOrEmpty(setStatment))
                        {
                            sb.AppendLine("UPDATE ");
                            sb.AppendLine("\t[" + t.GetSQLSchema() + "].[" + t.DatabaseName + "] ");
                            sb.AppendLine("SET");
                            sb.AppendLine(setStatment);
                            sb.AppendLine("WHERE");
                            sb.AppendLine("\t" + BuildUpdateWhereStatement(t, model, ((table.GetAbsoluteBaseTable() == t) && table.AllowTimestamp)));
                            sb.AppendLine();
                            sb.AppendLine("if (@@RowCount = 0) return;");
                            sb.AppendLine();
                        }
                    }
                }

                sb.AppendLine("SELECT");
                sb.Append(Globals.BuildSelectList(table, model, true));
                sb.AppendLine("FROM ");
                sb.AppendLine(table.GetFullHierarchyTableJoin());
                sb.AppendLine("WHERE");
				sb.AppendLine("\t" + BuildSelectWhereStatement(table, model));
                return sb.ToString();
            }
            public static string GetBody(Table table, ModelRoot model)
            {
                var sb = new StringBuilder();

                if (!table.Immutable)
                {
                    if (table.AllowCreateAudit)
                    {
                        sb.AppendLine("if (@" + model.Database.CreatedDateColumnName + " IS NULL)");
                        sb.AppendLine("SET @" + model.Database.CreatedDateColumnName + " = " + model.GetSQLDefaultDate());
                    }

                    if (table.AllowModifiedAudit)
                    {
					    if (model.EFVersion == EFVersionConstants.EF4)
					    {
	                        sb.AppendLine("DECLARE @" + model.Database.ModifiedDateColumnName + " [DateTime]");
	                        sb.AppendLine("SET @" + model.Database.ModifiedDateColumnName + " = " + model.GetSQLDefaultDate());
                    	}
                        else if (model.EFVersion == EFVersionConstants.EF6)
                        {
                            //Modified Date - This is where we override the placeholder parameter for EF6 runtime.
                            sb.Append("SET @" + model.Database.ModifiedDateColumnName + " = " + model.GetSQLDefaultDate());
                            sb.AppendLine("--Entity Framework 6 Required Modified Date be passed in, overwrite it here.");
                        }
                        else
                        {
                            throw new NotImplementedException(string.Format("model.EFVersion [{0}] not supported", model.EFVersion));
                        }
                    }

                    foreach (var column in table.PrimaryKeyColumns.OrderBy(x => x.Name))
                    {
                        if (column.Identity == IdentityTypeConstants.Code)
                        {
                            sb.AppendLine("SET @" + column.ToDatabaseCodeIdentifier() + " = (select case when max([" + column.DatabaseName + "]) is null then 1 else max([" + column.DatabaseName + "]) + 1 end from [" + Globals.GetTableDatabaseName(model, table) + "])");
                        }
                        else if (column.Identity == IdentityTypeConstants.Database)
                        {
                            //sb.AppendLine("DECLARE @" + column.ToDatabaseCodeIdentifier() + " " + dc.DataType);
                        }
                    }

                    if (table.ParentTable == null)
                    {
                        AppendInsertionStatement(sb, table, model);
                    }
                    else
                    {
                        var tableList = table.GetTableHierarchy();
                        foreach (var t in tableList)
                        {
                            AppendInsertionStatement(sb, t, model);
                            //On the base table save the primary keys as variables
                            if (t.ParentTable == null)
                                sb.Append(BuildInheritedPkBaseTableVariables(t, model));
                        }
                    }
                }

                sb.AppendLine();
                sb.AppendLine("SELECT ");
                sb.AppendLine(Globals.BuildSelectList(table, model, true));
                sb.AppendLine("FROM");
                sb.AppendLine(table.GetFullHierarchyTableJoin());
                sb.AppendLine("WHERE");
                sb.AppendLine("	" + BuildInsertSelectWhereStatement(table, model) + ";");
                return sb.ToString();
            }
        private void AppendTableClass(Table table)
        {
            try
            {
                var allTables = table.GetTableHierarchy();

                sb.AppendLine("	#region " + table.PascalName + "Include");
                sb.AppendLine();

                sb.AppendLine("	/// <summary>");
                sb.AppendLine("	/// This is a helper object for creating LINQ definitions for context includes on the " + table.PascalName + " collection.");
                sb.AppendLine("	/// </summary>");
                sb.AppendLine("	[Serializable]");
                sb.AppendLine("	[Table(Name = \"" + table.DatabaseName + "\")]");
                sb.AppendLine("	[System.CodeDom.Compiler.GeneratedCode(\"nHydrateModelGenerator\", \"" + _model.ModelToolVersion + "\")]");
                sb.AppendLine("	public partial class " + table.PascalName + "Include : nHydrate.EFCore.DataAccess.IContextInclude");
                sb.AppendLine("	{");

                //Add child relationships
                foreach (var relation in _model.Database.Relations.FindByParentTable(table, true).Where(x => x.IsGenerated))
                {
                    var parentTable = relation.ParentTableRef.Object as Table;
                    var childTable = relation.ChildTableRef.Object as Table;
                    if (parentTable.Generated && childTable.Generated)
                    {
                        if (childTable.AssociativeTable)
                        {
                            var middleTable = childTable;
                            var relationlist = middleTable.GetRelationsWhereChild();
                            if (relationlist.First() == relation)
                                childTable = (Table)relationlist.Last().ParentTableRef.Object;
                            else
                                childTable = (Table)relationlist.First().ParentTableRef.Object;

                            if (childTable.Generated &&
                                parentTable.Generated &&
                                !childTable.IsInheritedFrom(parentTable) &&
                                (!allTables.Contains(childTable)))
                            {
                                sb.AppendLine("		/// <summary>");
                                sb.AppendLine("		/// This is a mapping of the relationship with the " + childTable.PascalName + " entity. This is a N:M relation with two relationships though an intermediary table. (" + parentTable.PascalName + " -> " + middleTable.PascalName + " -> " + childTable.PascalName + ")");
                                sb.AppendLine("		/// </summary>");
                                //sb.AppendLine("		[Association(ThisKey = \"" + thisKey + "\", OtherKey = \"" + otherKey + "\")]");
                                if (relation.IsOneToOne && relation.AreAllFieldsPK)
                                    sb.AppendLine("		public " + this.GetLocalNamespace() + "." + childTable.PascalName + "Include " + relation.PascalRoleName + childTable.PascalName + " { get; private set; }");
                                else
                                    sb.AppendLine("		public " + this.GetLocalNamespace() + "." + childTable.PascalName + "Include " + relation.PascalRoleName + childTable.PascalName + "List { get; private set; }");
                            }
                        }
                        else
                        {
                            var thisKey = string.Empty;
                            var otherKey = string.Empty;
                            foreach (ColumnRelationship columnRelationship in relation.ColumnRelationships)
                            {
                                thisKey += ((Column)columnRelationship.ParentColumnRef.Object).PascalName + ",";
                                otherKey += ((Column)columnRelationship.ChildColumnRef.Object).PascalName + ",";
                            }
                            if (!string.IsNullOrEmpty(thisKey)) thisKey = thisKey.Substring(0, thisKey.Length - 1);
                            if (!string.IsNullOrEmpty(otherKey)) otherKey = otherKey.Substring(0, otherKey.Length - 1);

                            if (childTable.Generated &&
                                parentTable.Generated &&
                                !childTable.IsInheritedFrom(parentTable) &&
                                (!allTables.Contains(childTable)))
                            {
                                sb.AppendLine("		/// <summary>");
                                sb.AppendLine("		/// This is a mapping of the relationship with the " + childTable.PascalName + " entity." + (relation.PascalRoleName == "" ? "" : " (Role: '" + relation.RoleName + "')"));
                                sb.AppendLine("		/// </summary>");
                                sb.AppendLine("		[Association(ThisKey = \"" + thisKey + "\", OtherKey = \"" + otherKey + "\")]");
                                if (relation.IsOneToOne && relation.AreAllFieldsPK)
                                    sb.AppendLine("		public " + this.GetLocalNamespace() + "." + childTable.PascalName + "Include " + relation.PascalRoleName + childTable.PascalName + " { get; private set; }");
                                else
                                    sb.AppendLine("		public " + this.GetLocalNamespace() + "." + childTable.PascalName + "Include " + relation.PascalRoleName + childTable.PascalName + "List { get; private set; }");

                                sb.AppendLine();
                            }
                        }
                    }
                }

                //Add parent relationships
                foreach (var relation in _model.Database.Relations.FindByChildTable(table, true).Where(x => x.IsGenerated))
                {
                    var parentTable = (Table)relation.ParentTableRef.Object;
                    var childTable = (Table)relation.ChildTableRef.Object;

                    //Do not process self-referencing relationships
                    if (parentTable != table)
                    {
                        var thisKey = string.Empty;
                        var otherKey = string.Empty;
                        foreach (ColumnRelationship columnRelationship in relation.ColumnRelationships)
                        {
                            thisKey += ((Column)columnRelationship.ChildColumnRef.Object).PascalName + ",";
                            otherKey += ((Column)columnRelationship.ParentColumnRef.Object).PascalName + ",";
                        }
                        if (!string.IsNullOrEmpty(thisKey)) thisKey = thisKey.Substring(0, thisKey.Length - 1);
                        if (!string.IsNullOrEmpty(otherKey)) otherKey = otherKey.Substring(0, otherKey.Length - 1);

                        if (parentTable.Generated && (parentTable.TypedTable != TypedTableConstants.EnumOnly) && (!allTables.Contains(parentTable)))
                        {
                            sb.AppendLine("		/// <summary>");
                            sb.AppendLine("		/// This is a mapping of the relationship with the " + parentTable.PascalName + " entity." + (relation.PascalRoleName == "" ? "" : " (Role: '" + relation.RoleName + "')"));
                            sb.AppendLine("		/// </summary>");
                            sb.AppendLine("		[Association(ThisKey = \"" + thisKey + "\", OtherKey = \"" + otherKey + "\")]");
                            sb.AppendLine("		public " + this.GetLocalNamespace() + "." + parentTable.PascalName + "Include " + relation.PascalRoleName + parentTable.PascalName + " { get; private set; }");
                            sb.AppendLine();
                        }

                    }
                }

                sb.AppendLine("	}");
                sb.AppendLine();

                sb.AppendLine("	#endregion");
                sb.AppendLine();

            }
            catch (Exception ex)
            {
                throw;
            }
        }
示例#10
0
        public override void Refresh()
        {
            try
            {
                //BaseModelObject parent = (BaseModelObject)((nHydrate.Generator.Models.ReferenceCollection)(((nHydrate.Generator.Models.ColumnCollectionController)((nHydrate.Generator.Common.GeneratorFramework.ModelObjectTreeNode)this).Controller).Object)).Parent;
                if ((this.TreeView != null) && (this.TreeView.InvokeRequired))
                {
                    this.TreeView.Invoke(new EmptyDelegate(this.Refresh));
                    return;
                }

                if (this.TreeView != null)
                {
                    this.TreeView.BeginUpdate();
                }

                this.Text               = "Fields";
                this.Name               = "Fields";
                this.ImageIndex         = ImageHelper.GetImageIndex(TreeIconConstants.FolderClose);
                this.SelectedImageIndex = ImageHelper.GetImageIndex(TreeIconConstants.FolderOpen);

                //Add new nodes
                var   referenceCollection = (ReferenceCollection)this.Object;
                Table parentTable         = null;
                if (referenceCollection.Parent is Table)
                {
                    parentTable = (Table)referenceCollection.Parent;
                }

                //Save the selected item
                var selectedKey = string.Empty;
                if ((this.TreeView != null) && (this.TreeView.SelectedNode != null) && (this.Nodes.Contains(this.TreeView.SelectedNode)))
                {
                    var reference = referenceCollection.GetByKey(this.TreeView.SelectedNode.Name);
                    if (reference != null)
                    {
                        selectedKey = ((Column)reference.Object).Key;
                    }
                }

                var shallowColumnNames = new List <string>();
                var delList            = new List <Reference> ();
                foreach (Reference reference in referenceCollection)
                {
                    if (this.Nodes.Find(reference.Key, false).Length == 0)
                    {
                        if (reference.Object != null)
                        {
                            var column = (Column)reference.Object;
                            shallowColumnNames.Add(column.Name.ToLower());
                            this.AddColumnNode(reference, column);
                        }
                        else
                        {
                            delList.Add(reference);
                        }
                    }
                }
                referenceCollection.RemoveRange(delList);

                //Rename nodes if name change
                foreach (ColumnNode node in this.Nodes)
                {
                    var item = referenceCollection.FirstOrDefault(x => x.Key == node.Name);
                    if (item != null)
                    {
                        node.Text = ((Column)item.Object).Name;
                    }
                }

                //Remove non-existing nodes
                for (var ii = this.Nodes.Count - 1; ii >= 0; ii--)
                {
                    var node = (ColumnNode)this.Nodes[ii];
                    if (!referenceCollection.Contains(node.Name))
                    {
                        this.Nodes.RemoveAt(ii);
                    }
                }

                //Load the inherited columns
                if (parentTable != null)
                {
                    var allTables = new List <Table>(parentTable.GetTableHierarchy());
                    allTables.Remove(parentTable);

                    //Loop through all base tables and list columns that are NOT included in this table (the PK/audit columns)
                    foreach (var table in allTables)
                    {
                        foreach (var column in table.GeneratedColumns)
                        {
                            if (!shallowColumnNames.Contains(column.Name.ToLower()))
                            {
                                shallowColumnNames.Add(column.Name.ToLower());                                 //just in case, no duplicates
                                this.AddColumnNode(column);
                            }
                        }
                    }
                }

                //Save the selected item
                if ((this.TreeView != null) && (!string.IsNullOrEmpty(selectedKey)))
                {
                    foreach (TreeNode node in this.Nodes)
                    {
                        var reference = referenceCollection.GetByKey(node.Name);
                        if ((reference != null) && (selectedKey == ((Column)reference.Object).Key))
                        {
                            this.TreeView.SelectedNode = node;
                        }
                    }
                }

                this.Sort();

                this.Controller.UIControl.Refresh();
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                if (this.TreeView != null)
                {
                    this.TreeView.EndUpdate();
                }
            }
        }
EN | RU | DE | FR | ES | PT | IT | JP | ZH | KO