Пример #1
0
        private void ProcessInheritance(Entity entity, joinedsubclass newJoinedSubClass)
        {
            EntityImpl.InheritanceType inheritanceType = EntityImpl.DetermineInheritanceTypeWithChildren(entity);

            switch (inheritanceType)
            {
            case EntityImpl.InheritanceType.None:
            case EntityImpl.InheritanceType.TablePerConcreteClass:
                // Table per concrete class doesn't need special treatment.
                break;

            case EntityImpl.InheritanceType.TablePerClassHierarchy:
                // All child entities are mapped to the same table as the parent.
                //ProcessEntityTablePerClassHierarchy(entity, newJoinedSubClass);
                break;

            case EntityImpl.InheritanceType.TablePerSubClass:
                ProcessEntityTablePerSubClass(entity, newJoinedSubClass);
                break;

            case EntityImpl.InheritanceType.Unsupported:
                throw new Exception("An unsupported inheritance structure was detected. "
                                    + "We only support Table Per Class Hierarchy, Table Per Sub Class, and Table Per Concrete Class. "
                                    + "See the NHibernate documentation for more details.");

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #2
0
        private static bool SkipEntity_CheckChild(Entity entity)
        {
            EntityImpl.InheritanceType inheritanceType = EntityImpl.DetermineInheritanceTypeWithChildren(entity);

            switch (inheritanceType)
            {
            case EntityImpl.InheritanceType.None:
            case EntityImpl.InheritanceType.TablePerConcreteClass:
                return(false);

            case EntityImpl.InheritanceType.TablePerClassHierarchy:
            case EntityImpl.InheritanceType.TablePerSubClass:
            case EntityImpl.InheritanceType.Unsupported:
                return(true);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #3
0
        void centreShape_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Right)
            {
                HideAllContextMenuItems();

                EntityImpl.InheritanceType inheritanceType = EntityImpl.DetermineInheritanceTypeWithParent(Entity);

                if ((inheritanceType == EntityImpl.InheritanceType.None && (Entity.Children.Count == 0 || EntityImpl.DetermineInheritanceTypeWithChildren(Entity) == EntityImpl.InheritanceType.TablePerClassHierarchy)) ||
                    inheritanceType == EntityImpl.InheritanceType.TablePerClassHierarchy)
                {
                    if (Entity.Children.Count == 0 && Entity.Parent == null)
                    {
                        mnuCreateInheritanceHierarchy.Text = "Create inheritance hierarchy";
                    }
                    else
                    {
                        mnuCreateInheritanceHierarchy.Text = "Edit inheritance hierarchy";
                    }

                    mnuCreateInheritanceHierarchy.Visible = true;
                    contextMenuStrip1.BringToFront();
                    contextMenuStrip1.Show(Cursor.Position);
                }
                else
                {
                    var childInheritance = EntityImpl.DetermineInheritanceTypeWithChildren(Entity);

                    if (childInheritance == EntityImpl.InheritanceType.TablePerSubClass ||
                        childInheritance == EntityImpl.InheritanceType.TablePerSubClassWithDiscriminator)
                    {
                        mnuSetDiscriminatorForSubClass.Visible = true;
                        contextMenuStrip1.BringToFront();
                        contextMenuStrip1.Show(Cursor.Position);
                    }
                }
            }
        }
Пример #4
0
        void emptyChild_MouseClick(object sender, MouseEventArgs e)
        {
            if (e.Button != System.Windows.Forms.MouseButtons.Left)
            {
                return;
            }

            EntityImpl.InheritanceType inheritanceTypeWithChildren = EntityImpl.DetermineInheritanceTypeWithChildren(Entity);

            if (inheritanceTypeWithChildren == EntityImpl.InheritanceType.TablePerClassHierarchy)
            {
                ShowHierarchyEditor();
                return;
            }
            //if ((Entity.Children.Count > 0 && inheritanceTypeWithChildren == EntityImpl.InheritanceType.TablePerSubClass) ||
            //    inheritanceTypeWithChildren == EntityImpl.InheritanceType.TablePerConcreteClass ||
            //    inheritanceTypeWithChildren == EntityImpl.InheritanceType.TablePerClassHierarchy)// ||
            //{
            SelectedParent = null;
            SelectedChild  = null;

            List <Entity> unavailableEntities = new List <Entity>();

            unavailableEntities.AddRange(Entity.Children);

            if (Entity.Parent != null)
            {
                unavailableEntities.Add(Entity.Parent);
            }

            UserControls.FormSelectEntityForInheritance form = new UserControls.FormSelectEntityForInheritance(Entity, unavailableEntities, null, "Select child entities", true, UserControls.FormSelectEntityForInheritance.RequestorTypes.Entity_Select_Child);
            form.EntityDeleted += new EventHandler(form_EntityDeleted);
            form.ShowDialog();

            if (form.SelectedEntities != null && form.SelectedEntities.Count > 0)
            {
                foreach (var entity in form.SelectedEntities)
                {
                    Entity.AddChild(entity);
                    entity.Parent = Entity;

                    foreach (var directedReference in Entity.DirectedReferences)
                    {
                        if (directedReference.ToEntity == entity)
                        {
                            Entity.RemoveReference(directedReference.Reference);
                            directedReference.Reference.DeleteSelf();
                        }
                    }
                    foreach (var directedReference in entity.DirectedReferences)
                    {
                        if (directedReference.ToEntity == Entity)
                        {
                            entity.RemoveReference(directedReference.Reference);
                            directedReference.Reference.DeleteSelf();
                        }
                    }
                    // Remove the ID property from the child entity because it should share the parent entity's ID instead
                    for (int i = entity.Key.Properties.ToList().Count - 1; i >= 0; i--)
                    {
                        if (Entity.IsAbstract)
                        {
                            entity.Key.Properties.ElementAt(i).IsHiddenByAbstractParent = true;
                        }
                        else
                        {
                            entity.Key.Properties.ElementAt(i).IsPartOfHiddenKey = true;
                        }
                    }
                    if (Entity.IsAbstract)
                    {
                        foreach (Property parentProp in Entity.Properties)
                        {
                            Property childProp = entity.ConcreteProperties.SingleOrDefault(p => p.Name == parentProp.Name);

                            if (childProp != null)
                            {
                                childProp.IsHiddenByAbstractParent = true;
                            }
                        }
                    }
                }
                form.EntityDeleted -= form_EntityDeleted;
                Populate();

                RaiseInheritanceUpdatedEvent();
            }
            //}
            //else if (!HasOneToOne)
            //{
            //UserControls.FormInheritanceHierarchy form = new UserControls.FormInheritanceHierarchy(Entity);
            //form.ShowDialog(this);
            //}
        }
Пример #5
0
        public IValidationResult Run(MappingSet set)
        {
            var result = new ValidationResult(this);

            foreach (var entity in set.EntitySet.Entities)
            {
                var mappedTables = entity.MappedTables();

                var primaryColumns        = mappedTables.SelectMany(t => t.ColumnsInPrimaryKey);
                var propertyMappedColumns = entity.Properties.Concat(entity.PropertiesHiddenByAbstractParent).Select(p => p.MappedColumn()).Where(c => c != null);

                // This gets all of the component properties, and selects the non null mapped components.
                var componentMappedColumns =
                    entity.Components.SelectMany(c => c.Properties).Select(p => p.MappedColumn()).Where(c => c != null);

                var mappedColumns = propertyMappedColumns.Concat(componentMappedColumns).ToLookup(c => c.InternalIdentifier);

                // Only one of the MappedTables needs their primary key columns mapped, because the other MappedTables
                // should have relationships with the primary mappedTable.
                bool oneFound = mappedTables.Count() == 0;

                foreach (var mappedTable in mappedTables)
                {
                    bool allPrimaryKeyColumnsFound = true;

                    foreach (var primaryColumn in mappedTable.ColumnsInPrimaryKey)                    // primaryColumns)
                    {
                        if (mappedColumns.Contains(primaryColumn.InternalIdentifier) == false)
                        {
                            allPrimaryKeyColumnsFound = false;
                            break;
                        }
                    }
                    if (allPrimaryKeyColumnsFound)
                    {
                        oneFound = true;
                        break;
                    }
                }
                if (!oneFound)
                {
                    EntityImpl.InheritanceType inheritanceType = EntityImpl.DetermineInheritanceTypeWithParent(entity);

                    if (inheritanceType == EntityImpl.InheritanceType.TablePerSubClass ||
                        inheritanceType == EntityImpl.InheritanceType.TablePerConcreteClass)
                    {
                        if (mappedTables.Count() == 1)
                        {
                            Model.DatabaseLayer.ITable table = mappedTables.ElementAt(0);

                            if (table.FirstPrimaryKey != null)
                            {
                                // All ok
                                continue;
                            }
                        }
                    }
                    string tables = "";

                    foreach (var name in mappedTables.Select(t => t.Name))
                    {
                        tables += name + ", ";
                    }

                    tables = tables.TrimEnd(',', ' ');

                    result.Issues.Add(new ValidationIssue(
                                          string.Format("Entity {0} is mapped to Tables [{1}] but doesn't have a property mapped to any primary key columns.", entity.Name, tables),
                                          entity, ValidationErrorLevel.Error));
                }
            }
            return(result);
        }