private Entity CreateNewEntityFromTable(ITable table) { List <ITable> tablesToProcess = new List <ITable>(); tablesToProcess.Add(table); EntityModel.Controller.MappingLayer.MappingProcessor proc = new EntityModel.Controller.MappingLayer.MappingProcessor(new EntityModel.Controller.MappingLayer.OneToOneEntityProcessor(table.Database.MappingSet.EntitySet.Entities.Select(ent => ent.Name))); List <Entity> newEntities = proc.CreateOneToOneMappingsFor(tablesToProcess, table.Database.MappingSet); if (newEntities.Count != 1) { throw new Exception("Only one entity should be created."); } return(newEntities[0]); }
internal bool Save() { if (comboBoxDiscriminatorType.SelectedItem.ToString() == "Column" && comboBoxDiscriminator.SelectedIndex < 0) { MessageBox.Show(this, "Select a discriminator column.", "Missing data", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } else if (comboBoxDiscriminatorType.SelectedItem.ToString() == "Formula" && string.IsNullOrWhiteSpace(textBoxFormula.Text)) { MessageBox.Show(this, "Enter a formula.", "Missing data", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } #region Check for entities with no columns selected List <string> entitiesWithNoColumns = new List <string>(); for (int i = 1; i < advTree1.Columns.Count; i++) { bool hasSelectedColumns = false; for (int rowIndex = 3; rowIndex < advTree1.Nodes.Count; rowIndex++) { if (advTree1.Nodes[rowIndex].Cells[i].Checked) { hasSelectedColumns = true; break; } } if (!hasSelectedColumns) { entitiesWithNoColumns.Add(((DevComponents.DotNetBar.Controls.TextBoxX)advTree1.Nodes[0].Cells[i].HostedControl).Text); } } if (entitiesWithNoColumns.Count > 0) { string message = "Entites with no columns. Delete them or select some columns: " + Environment.NewLine + Environment.NewLine; foreach (var entityname in entitiesWithNoColumns) { message += entityname + ", "; } message = message.TrimEnd(' ', ','); MessageBox.Show(this, message, "Entities with no columns", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } #endregion #region Check that exactly one Base exists bool baseFound = false; int baseIndex = -1; for (int i = 1; i < advTree1.Columns.Count; i++) { if (((DevComponents.DotNetBar.CheckBoxItem)advTree1.Nodes[1].Cells[i].HostedItem).Checked) { baseFound = true; baseIndex = i; break; } } if (!baseFound) { MessageBox.Show(this, "Specify a base entity.", "Missing data", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } #endregion EditModel.BusyPopulating = true; Entity baseEntity = null; List <Entity> childEntities = new List <Entity>(); // Save all the entities for (int i = 1; i < advTree1.Columns.Count; i++) { Entity entity = (Entity)advTree1.Columns[i].Tag; if (entity.EntitySet == null) // This is a new entity { // Create a new entity List <ITable> tablesToProcess = new List <ITable>(); tablesToProcess.Add(Table); EntityModel.Controller.MappingLayer.MappingProcessor proc = new EntityModel.Controller.MappingLayer.MappingProcessor(new EntityModel.Controller.MappingLayer.OneToOneEntityProcessor()); List <Entity> newEntities = proc.CreateOneToOneMappingsFor(tablesToProcess, Table.Database.MappingSet); if (newEntities.Count != 1) { throw new Exception("Only one entity should be created."); } Entity newEntity = newEntities[0]; newEntity.Name = ((DevComponents.DotNetBar.Controls.TextBoxX)advTree1.Nodes[0].Cells[i].HostedControl).Text; newEntity.DiscriminatorValue = ((DevComponents.DotNetBar.Controls.TextBoxX)advTree1.Nodes[2].Cells[i].HostedControl).Text; UpdateProperties(i, newEntity); // Delete the original entity entity.DeleteSelf(); entity = newEntity; } else // This is an existing entity { entity.Name = ((DevComponents.DotNetBar.Controls.TextBoxX)advTree1.Nodes[0].Cells[i].HostedControl).Text; UpdateProperties(i, entity); } if (i == baseIndex) { baseEntity = entity; } else { childEntities.Add(entity); } } foreach (Entity child in childEntities) { child.Parent = baseEntity; baseEntity.AddChild(child); } if (comboBoxDiscriminatorType.SelectedItem.ToString() == "Column") { baseEntity.Discriminator.DiscriminatorType = Enums.DiscriminatorTypes.Column; baseEntity.Discriminator.ColumnName = comboBoxDiscriminator.SelectedItem.ToString(); } else { baseEntity.Discriminator.DiscriminatorType = Enums.DiscriminatorTypes.Formula; baseEntity.Discriminator.Formula = textBoxFormula.Text; } EditModel.BusyPopulating = false; return(true); }
private bool CreateNewEntity() { if (textBoxName.Text == "NewName") { MessageBox.Show(this, "You need specify a name for the new entity.", "Invalid name", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } if (Table.Database.MappingSet.EntitySet.Entities.Any(e => e.Name.ToLowerInvariant() == textBoxName.Text.ToLowerInvariant())) { MessageBox.Show(this, "An entity with this name already exists.", "Invalid name", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } if (RequestorType == RequestorTypes.Table) { if (listViewEx1.CheckedItems.Count == 0) { MessageBox.Show(this, "You need to select at least one property.", "No properties selected", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } // Check if this table is currently used as an association table var reference = Table.Database.MappingSet.EntitySet.References.FirstOrDefault(r => r.MappedTable() == Table); bool keepAssociationEntities = false; if (reference != null) { if (MessageBox.Show(this, string.Format("This table is currently being used as an association table to implement a many-to-many relationship between {0} and {1} and therefore should normally have no mapped entity.\n\nAre you sure you want to create a new entity for it?", reference.Entity1.Name, reference.Entity2.Name), "Association table", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.No) return false; else keepAssociationEntities = true; } List<ITable> tablesToProcess = new List<ITable>(); tablesToProcess.Add(Table); EntityModel.Controller.MappingLayer.MappingProcessor proc = new EntityModel.Controller.MappingLayer.MappingProcessor(new EntityModel.Controller.MappingLayer.OneToOneEntityProcessor(Table.Database.MappingSet.EntitySet.Entities.Select(ent => ent.Name))); List<Entity> newEntities = proc.CreateOneToOneMappingsFor(tablesToProcess, Table.Database.MappingSet, keepAssociationEntities); SelectedEntity = newEntities[0]; #region Remove un-selected columns List<string> selectedColumnNames = new List<string>(); foreach (ListViewItem col in listViewEx1.CheckedItems) selectedColumnNames.Add(col.Text); for (int i = SelectedEntity.Properties.Count() - 1; i >= 0; i--) { Property property = SelectedEntity.Properties.ElementAt(i); var mappedColumn = property.MappedColumn(); if (mappedColumn != null && !selectedColumnNames.Contains(mappedColumn.Name)) SelectedEntity.RemoveProperty(property); } #endregion SelectedEntity.Name = textBoxName.Text; return true; } else //else if (RequestorType == RequestorTypes.Entity_Select_Parent || // RequestorType == RequestorTypes.Entity_Create_Abstract_Parent) { Entity newEntity = new EntityImpl(textBoxName.Text) { Schema = Entity.Schema }; Entity.EntitySet.AddEntity(newEntity); SelectedEntity = newEntity; return true; } //else if (RequestorType == RequestorTypes.Entity_Select_Child) //{ // if (SelectedItems.Count == 0) // { // MessageBox.Show(this, "You need to select some child entities.", "No entities selected", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return false; // } // Entity newEntity = new EntityImpl("NewChildEntity") { Schema = Entity.Schema }; // foreach (ListViewItem item in SelectedItems) // { // Property existingProperty = (Property)item.Tag; // newEntity.AddProperty(new PropertyImpl(existingProperty.Name) // { // Type = existingProperty.Type // }); // } // //newEntity.AddChild(Entity); // //Entity.Parent = newEntity; // Entity.EntitySet.AddEntity(newEntity); // SelectedEntity = newEntity; // return true; //} //else // throw new NotImplementedException("RequestorType not handled yet: " + RequestorType.ToString()); }
private bool CreateNewEntity() { if (textBoxName.Text == "NewName") { MessageBox.Show(this, "You need specify a name for the new entity.", "Invalid name", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } if (Table.Database.MappingSet.EntitySet.Entities.Any(e => e.Name.ToLowerInvariant() == textBoxName.Text.ToLowerInvariant())) { MessageBox.Show(this, "An entity with this name already exists.", "Invalid name", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } if (RequestorType == RequestorTypes.Table) { if (listViewEx1.CheckedItems.Count == 0) { MessageBox.Show(this, "You need to select at least one property.", "No properties selected", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } // Check if this table is currently used as an association table var reference = Table.Database.MappingSet.EntitySet.References.FirstOrDefault(r => r.MappedTable() == Table); bool keepAssociationEntities = false; if (reference != null) { if (MessageBox.Show(this, string.Format("This table is currently being used as an association table to implement a many-to-many relationship between {0} and {1} and therefore should normally have no mapped entity.\n\nAre you sure you want to create a new entity for it?", reference.Entity1.Name, reference.Entity2.Name), "Association table", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == System.Windows.Forms.DialogResult.No) { return(false); } else { keepAssociationEntities = true; } } List <ITable> tablesToProcess = new List <ITable>(); tablesToProcess.Add(Table); EntityModel.Controller.MappingLayer.MappingProcessor proc = new EntityModel.Controller.MappingLayer.MappingProcessor(new EntityModel.Controller.MappingLayer.OneToOneEntityProcessor(Table.Database.MappingSet.EntitySet.Entities.Select(ent => ent.Name))); List <Entity> newEntities = proc.CreateOneToOneMappingsFor(tablesToProcess, Table.Database.MappingSet, keepAssociationEntities); SelectedEntity = newEntities[0]; #region Remove un-selected columns List <string> selectedColumnNames = new List <string>(); foreach (ListViewItem col in listViewEx1.CheckedItems) { selectedColumnNames.Add(col.Text); } for (int i = SelectedEntity.Properties.Count() - 1; i >= 0; i--) { Property property = SelectedEntity.Properties.ElementAt(i); var mappedColumn = property.MappedColumn(); if (mappedColumn != null && !selectedColumnNames.Contains(mappedColumn.Name)) { SelectedEntity.RemoveProperty(property); } } #endregion SelectedEntity.Name = textBoxName.Text; return(true); } else //else if (RequestorType == RequestorTypes.Entity_Select_Parent || // RequestorType == RequestorTypes.Entity_Create_Abstract_Parent) { Entity newEntity = new EntityImpl(textBoxName.Text) { Schema = Entity.Schema }; Entity.EntitySet.AddEntity(newEntity); SelectedEntity = newEntity; return(true); } //else if (RequestorType == RequestorTypes.Entity_Select_Child) //{ // if (SelectedItems.Count == 0) // { // MessageBox.Show(this, "You need to select some child entities.", "No entities selected", MessageBoxButtons.OK, MessageBoxIcon.Warning); // return false; // } // Entity newEntity = new EntityImpl("NewChildEntity") { Schema = Entity.Schema }; // foreach (ListViewItem item in SelectedItems) // { // Property existingProperty = (Property)item.Tag; // newEntity.AddProperty(new PropertyImpl(existingProperty.Name) // { // Type = existingProperty.Type // }); // } // //newEntity.AddChild(Entity); // //Entity.Parent = newEntity; // Entity.EntitySet.AddEntity(newEntity); // SelectedEntity = newEntity; // return true; //} //else // throw new NotImplementedException("RequestorType not handled yet: " + RequestorType.ToString()); }
private bool CreateNewEntity() { if (RequestorType == RequestorTypes.Table) { List <ITable> tablesToProcess = new List <ITable>(); tablesToProcess.Add(Table); EntityModel.Controller.MappingLayer.MappingProcessor proc = new EntityModel.Controller.MappingLayer.MappingProcessor(new EntityModel.Controller.MappingLayer.OneToOneEntityProcessor(Table.Database.MappingSet.EntitySet.Entities.Select(ent => ent.Name))); List <Entity> newEntities = proc.CreateOneToOneMappingsFor(tablesToProcess, Table.Database.MappingSet); SelectedEntity = newEntities[0]; #region Remove un-selected columns List <string> selectedColumnNames = new List <string>(); foreach (ListViewItem col in listViewEntities.CheckedItems) { selectedColumnNames.Add(col.Text); } for (int i = SelectedEntity.Properties.Count() - 1; i >= 0; i--) { Property property = SelectedEntity.Properties.ElementAt(i); if (!selectedColumnNames.Contains(property.MappedColumn().Name)) { SelectedEntity.RemoveProperty(property); } } #endregion SelectedEntity.Name = textBoxName.Text; return(true); } else if (RequestorType == RequestorTypes.Entity_Select_Parent || RequestorType == RequestorTypes.Entity_Create_Abstract_Parent) { if (SelectedPropertyItems.Count == 0) { MessageBox.Show(this, "You need to select some properties to be moved into the abstract parent (Table Per Concrete Class)", "No properties selected", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } if (RequestorType == RequestorTypes.Entity_Create_Abstract_Parent && string.IsNullOrWhiteSpace(textBoxName.Text) || textBoxName.Text == DefaultNewAbstractParentName) { MessageBox.Show(this, "Please enter a name for the new abstract parent entity.", "Name missing", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } Entity newEntity = new EntityImpl(textBoxName.Text) { Schema = Entity.Schema }; newEntity.IsAbstract = true; // Check that all key-properties are selected List <Property> selectedProperties = new List <Property>(); foreach (ListViewItem item in SelectedPropertyItems) { selectedProperties.Add((Property)item.Tag); } List <Property> unselectedKepProperties = new List <Property>(); foreach (Property prop in Entity.Properties) { if (prop.IsKeyProperty && !selectedProperties.Contains(prop)) { unselectedKepProperties.Add(prop); } } if (unselectedKepProperties.Count > 0) { string keyPropNames = ""; foreach (Property p in unselectedKepProperties) { keyPropNames += p.Name + ", "; } MessageBox.Show(this, "All key properties need to be selected: " + keyPropNames.TrimEnd(',', ' '), "Invalid selection", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } foreach (ListViewItem item in SelectedPropertyItems) { Property existingProperty = (Property)item.Tag; PropertyImpl newProp = new PropertyImpl(existingProperty.Name) { Type = existingProperty.Type, NHibernateType = existingProperty.NHibernateType, IsKeyProperty = existingProperty.IsKeyProperty }; //newProp.SetMappedColumn(existingProperty.MappedColumn()); newEntity.AddProperty(newProp); //newEntity.AddProperty(existingProperty); // Remove this property from the existing Entity, as it's now been added to the parent //if (existingProperty.IsKeyProperty) existingProperty.IsHiddenByAbstractParent = true; //else // Entity.RemoveProperty(existingProperty); } //newEntity.AddChild(Entity); //Entity.Parent = newEntity; Entity.EntitySet.AddEntity(newEntity); SelectedEntity = newEntity; return(true); } else if (RequestorType == RequestorTypes.Entity_Select_Child) { if (SelectedPropertyItems.Count == 0) { MessageBox.Show(this, "You need to select some child entities.", "No entities selected", MessageBoxButtons.OK, MessageBoxIcon.Warning); return(false); } Entity newEntity = new EntityImpl("NewChildEntity") { Schema = Entity.Schema }; foreach (ListViewItem item in SelectedPropertyItems) { Property existingProperty = (Property)item.Tag; newEntity.AddProperty(new PropertyImpl(existingProperty.Name) { Type = existingProperty.Type, NHibernateType = existingProperty.NHibernateType }); } //newEntity.AddChild(Entity); //Entity.Parent = newEntity; Entity.EntitySet.AddEntity(newEntity); SelectedEntity = newEntity; return(true); } else { throw new NotImplementedException("RequestorType not handled yet: " + RequestorType.ToString()); } }
internal bool Save() { if (comboBoxDiscriminatorType.SelectedItem.ToString() == "Column" && comboBoxDiscriminator.SelectedIndex < 0) { MessageBox.Show(this, "Select a discriminator column.", "Missing data", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } else if (comboBoxDiscriminatorType.SelectedItem.ToString() == "Formula" && string.IsNullOrWhiteSpace(textBoxFormula.Text)) { MessageBox.Show(this, "Enter a formula.", "Missing data", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } #region Check for entities with no columns selected List<string> entitiesWithNoColumns = new List<string>(); for (int i = 1; i < advTree1.Columns.Count; i++) { bool hasSelectedColumns = false; for (int rowIndex = 3; rowIndex < advTree1.Nodes.Count; rowIndex++) { if (advTree1.Nodes[rowIndex].Cells[i].Checked) { hasSelectedColumns = true; break; } } if (!hasSelectedColumns) entitiesWithNoColumns.Add(((DevComponents.DotNetBar.Controls.TextBoxX)advTree1.Nodes[0].Cells[i].HostedControl).Text); } if (entitiesWithNoColumns.Count > 0) { string message = "Entites with no columns. Delete them or select some columns: " + Environment.NewLine + Environment.NewLine; foreach (var entityname in entitiesWithNoColumns) message += entityname + ", "; message = message.TrimEnd(' ', ','); MessageBox.Show(this, message, "Entities with no columns", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } #endregion #region Check that exactly one Base exists bool baseFound = false; int baseIndex = -1; for (int i = 1; i < advTree1.Columns.Count; i++) { if (((DevComponents.DotNetBar.CheckBoxItem)advTree1.Nodes[1].Cells[i].HostedItem).Checked) { baseFound = true; baseIndex = i; break; } } if (!baseFound) { MessageBox.Show(this, "Specify a base entity.", "Missing data", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } #endregion EditModel.BusyPopulating = true; Entity baseEntity = null; List<Entity> childEntities = new List<Entity>(); // Save all the entities for (int i = 1; i < advTree1.Columns.Count; i++) { Entity entity = (Entity)advTree1.Columns[i].Tag; if (entity.EntitySet == null) // This is a new entity { // Create a new entity List<ITable> tablesToProcess = new List<ITable>(); tablesToProcess.Add(Table); EntityModel.Controller.MappingLayer.MappingProcessor proc = new EntityModel.Controller.MappingLayer.MappingProcessor(new EntityModel.Controller.MappingLayer.OneToOneEntityProcessor()); List<Entity> newEntities = proc.CreateOneToOneMappingsFor(tablesToProcess, Table.Database.MappingSet); if (newEntities.Count != 1) throw new Exception("Only one entity should be created."); Entity newEntity = newEntities[0]; newEntity.Name = ((DevComponents.DotNetBar.Controls.TextBoxX)advTree1.Nodes[0].Cells[i].HostedControl).Text; newEntity.DiscriminatorValue = ((DevComponents.DotNetBar.Controls.TextBoxX)advTree1.Nodes[2].Cells[i].HostedControl).Text; UpdateProperties(i, newEntity); // Delete the original entity entity.DeleteSelf(); entity = newEntity; } else // This is an existing entity { entity.Name = ((DevComponents.DotNetBar.Controls.TextBoxX)advTree1.Nodes[0].Cells[i].HostedControl).Text; UpdateProperties(i, entity); } if (i == baseIndex) baseEntity = entity; else childEntities.Add(entity); } foreach (Entity child in childEntities) { child.Parent = baseEntity; baseEntity.AddChild(child); } if (comboBoxDiscriminatorType.SelectedItem.ToString() == "Column") { baseEntity.Discriminator.DiscriminatorType = Enums.DiscriminatorTypes.Column; baseEntity.Discriminator.ColumnName = comboBoxDiscriminator.SelectedItem.ToString(); } else { baseEntity.Discriminator.DiscriminatorType = Enums.DiscriminatorTypes.Formula; baseEntity.Discriminator.Formula = textBoxFormula.Text; } EditModel.BusyPopulating = false; return true; }
private bool CreateNewEntity() { if (RequestorType == RequestorTypes.Table) { List<ITable> tablesToProcess = new List<ITable>(); tablesToProcess.Add(Table); EntityModel.Controller.MappingLayer.MappingProcessor proc = new EntityModel.Controller.MappingLayer.MappingProcessor(new EntityModel.Controller.MappingLayer.OneToOneEntityProcessor(Table.Database.MappingSet.EntitySet.Entities.Select(ent => ent.Name))); List<Entity> newEntities = proc.CreateOneToOneMappingsFor(tablesToProcess, Table.Database.MappingSet); SelectedEntity = newEntities[0]; #region Remove un-selected columns List<string> selectedColumnNames = new List<string>(); foreach (ListViewItem col in listViewEntities.CheckedItems) selectedColumnNames.Add(col.Text); for (int i = SelectedEntity.Properties.Count() - 1; i >= 0; i--) { Property property = SelectedEntity.Properties.ElementAt(i); if (!selectedColumnNames.Contains(property.MappedColumn().Name)) SelectedEntity.RemoveProperty(property); } #endregion SelectedEntity.Name = textBoxName.Text; return true; } else if (RequestorType == RequestorTypes.Entity_Select_Parent || RequestorType == RequestorTypes.Entity_Create_Abstract_Parent) { if (SelectedPropertyItems.Count == 0) { MessageBox.Show(this, "You need to select some properties to be moved into the abstract parent (Table Per Concrete Class)", "No properties selected", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } if (RequestorType == RequestorTypes.Entity_Create_Abstract_Parent && string.IsNullOrWhiteSpace(textBoxName.Text) || textBoxName.Text == DefaultNewAbstractParentName) { MessageBox.Show(this, "Please enter a name for the new abstract parent entity.", "Name missing", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } Entity newEntity = new EntityImpl(textBoxName.Text) { Schema = Entity.Schema }; newEntity.IsAbstract = true; // Check that all key-properties are selected List<Property> selectedProperties = new List<Property>(); foreach (ListViewItem item in SelectedPropertyItems) selectedProperties.Add((Property)item.Tag); List<Property> unselectedKepProperties = new List<Property>(); foreach (Property prop in Entity.Properties) if (prop.IsKeyProperty && !selectedProperties.Contains(prop)) unselectedKepProperties.Add(prop); if (unselectedKepProperties.Count > 0) { string keyPropNames = ""; foreach (Property p in unselectedKepProperties) keyPropNames += p.Name + ", "; MessageBox.Show(this, "All key properties need to be selected: " + keyPropNames.TrimEnd(',', ' '), "Invalid selection", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } foreach (ListViewItem item in SelectedPropertyItems) { Property existingProperty = (Property)item.Tag; PropertyImpl newProp = new PropertyImpl(existingProperty.Name) { Type = existingProperty.Type, NHibernateType = existingProperty.NHibernateType, IsKeyProperty = existingProperty.IsKeyProperty }; //newProp.SetMappedColumn(existingProperty.MappedColumn()); newEntity.AddProperty(newProp); //newEntity.AddProperty(existingProperty); // Remove this property from the existing Entity, as it's now been added to the parent //if (existingProperty.IsKeyProperty) existingProperty.IsHiddenByAbstractParent = true; //else // Entity.RemoveProperty(existingProperty); } //newEntity.AddChild(Entity); //Entity.Parent = newEntity; Entity.EntitySet.AddEntity(newEntity); SelectedEntity = newEntity; return true; } else if (RequestorType == RequestorTypes.Entity_Select_Child) { if (SelectedPropertyItems.Count == 0) { MessageBox.Show(this, "You need to select some child entities.", "No entities selected", MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } Entity newEntity = new EntityImpl("NewChildEntity") { Schema = Entity.Schema }; foreach (ListViewItem item in SelectedPropertyItems) { Property existingProperty = (Property)item.Tag; newEntity.AddProperty(new PropertyImpl(existingProperty.Name) { Type = existingProperty.Type, NHibernateType = existingProperty.NHibernateType }); } //newEntity.AddChild(Entity); //Entity.Parent = newEntity; Entity.EntitySet.AddEntity(newEntity); SelectedEntity = newEntity; return true; } else throw new NotImplementedException("RequestorType not handled yet: " + RequestorType.ToString()); }