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
Exemplo n.º 1
0
        /// <summary>
        /// Find all relationships that have a specific child table
        /// </summary>
        /// <param name="entity">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 IList <EntityHasEntities> FindByChildTable(Entity entity, bool includeHierarchy)
        {
            try
            {
                var retval     = new List <EntityHasEntities>();
                var tableList  = new List <Entity>();
                var columnList = new List <Field>();
                if (includeHierarchy)
                {
                    tableList.AddRange(entity.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 <Entity>();
                    tableList.Add(entity);
                    columnList.AddRange(entity.Fields);
                }

                foreach (var relation in this.Store.ElementDirectory.AllElements.Where(x => x is EntityHasEntities).Cast <EntityHasEntities>())
                {
                    var childTable = relation.TargetEntity;
                    foreach (var columnRelationship in relation.FieldMapList())
                    {
                        foreach (var column in columnList)
                        {
                            if (tableList.Contains(childTable))
                            {
                                if (!retval.Contains(relation))
                                {
                                    retval.Add(relation);
                                }
                            }
                        }
                    }
                }

                return(retval.AsReadOnly());
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Find all relationships that have a specific child table
        /// </summary>
        /// <param name="entity">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 IList<EntityHasEntities> FindByChildTable(Entity entity, bool includeHierarchy)
        {
            try
            {
                var retval = new List<EntityHasEntities>();
                var tableList = new List<Entity>();
                var columnList = new List<Field>();
                if (includeHierarchy)
                {
                    tableList.AddRange(entity.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<Entity>();
                    tableList.Add(entity);
                    columnList.AddRange(entity.Fields);
                }

                foreach (var relation in this.Store.ElementDirectory.AllElements.Where(x => x is EntityHasEntities).Cast<EntityHasEntities>())
                {
                    var childTable = relation.TargetEntity;
                    foreach (var columnRelationship in relation.FieldMapList())
                    {
                        foreach (var column in columnList)
                        {
                            if (tableList.Contains(childTable))
                            {
                                if (!retval.Contains(relation))
                                    retval.Add(relation);
                            }
                        }
                    }
                }

                return retval.AsReadOnly();
            }
            catch (Exception ex)
            {
                throw;
            }
        }