public void The_Correct_Entities_Are_Created2() { MappingSet mappings = CreateMappingSet_TwoTables(); EntitySet entities = mappings.EntitySet; IDatabase database = mappings.Database; ITable table1 = database.Tables[0]; ITable table2 = database.Tables[1]; Assert.That(mappings.Database, Is.SameAs(database)); Assert.That(entities, Is.Not.Null); Assert.That(entities, Has.Count(2)); Assert.That(entities[0].EntitySet, Is.SameAs(entities)); Assert.That(entities[1].EntitySet, Is.SameAs(entities)); Assert.That(mappings.Mappings.Count, Is.EqualTo(2)); var mapping0 = mappings.Mappings[0]; Assert.That(mapping0.ToEntity, Is.SameAs(entities[0])); Assert.That(mapping0.ToProperties.Count() == 1); Assert.That(mapping0.ToProperties[0], Is.SameAs(entities[0].Properties.ElementAt(0))); Assert.That(mapping0.FromTable, Is.SameAs(table1)); Assert.That(mapping0.FromColumns.Count() == 1); Assert.That(mapping0.FromColumns[0], Is.SameAs(table1.Columns[0])); var mapping1 = mappings.Mappings[1]; Assert.That(mapping1.ToEntity, Is.SameAs(entities[1])); Assert.That(mapping1.ToProperties.Count() == 1); Assert.That(mapping1.ToProperties[0], Is.SameAs(entities[1].Properties.ElementAt(0))); Assert.That(mapping1.FromTable, Is.SameAs(table2)); Assert.That(mapping1.FromColumns.Count() == 1); Assert.That(mapping1.FromColumns[0], Is.SameAs(table2.Columns[0])); }
public void loadMappingSet(MappingSet mappingSet) { //set current mapping Set this.mappingSet = mappingSet; //clear the list clear(); //add the mappings foreach (var mapping in mappingSet.mappings) { //sourcePath ListViewItem listViewItem = new ListViewItem(mapping.source.mappingPath); //source type listViewItem.SubItems.Add(mapping.source.mappedEnd.GetType().Name); //source listViewItem.SubItems.Add(mapping.source.mappedEnd.name); //mapping logic listViewItem.SubItems.Add(mapping.mappingLogic != null ? mapping.mappingLogic.description : string.Empty); //target listViewItem.SubItems.Add(mapping.target.mappedEnd.name); //target type listViewItem.SubItems.Add(mapping.target.mappedEnd.GetType().Name); //target path listViewItem.SubItems.Add(mapping.target.mappingPath); //set tag listViewItem.Tag = mapping; //add the item to the grid this.mappingListView.Items.Add(listViewItem); } }
public void ApplyChanges(MappingSet mappingSet, EntityKey key) { // Create new Component var component = existingSpecToUse.CreateImplementedComponentFor(key.Parent, newComponentName); // Set mapped column on the new Component's properties. foreach (var pair in propertyMappings) { var newProperty = component.GetProperty(pair.Key); var oldProperty = key.Properties.FirstOrDefault(p => p.Name == pair.Value); if (oldProperty == null) { // Something went horribly wrong. We have a Property that has been mapped, // but it doesn't actually exist. I am chosing to ignore this here, but log it. log.ErrorFormat("Property {0} was mapped in the ConvertKeyToComponent wizard, but doesn't actually exist in the model.", pair.Value); continue; } newProperty.SetMappedColumn(oldProperty.MappedColumn()); } // Delete existing properties if needed. if (deleteExistingProperties) { foreach (var property in key.Properties.ToList()) { property.DeleteSelf(); } } key.Component = component; }
public void SetUp() { loader = new EntityLoader(MockRepository.GenerateStub <IFileController>()); database = new Database("DB1"); table = new Table("Transport"); table.AddColumn(new Column("ID") { Datatype = "int" }); table.AddColumn(new Column("Discriminator") { Datatype = "char", Size = 1 }); table.AddColumn(new Column("Name") { Datatype = "varchar", Size = 100 }); table.AddColumn(new Column("Bike_Code") { Datatype = "varchar", Size = 5 }); database.AddEntity(table); // Call we are testing mappingSet = loader.GetEntities(new[] { Path.Combine("Resources", "TablePerClassHierarchy.hbm.xml") }, database); }
public IValidationResult Run(MappingSet set) { IValidationResult result = new ValidationResult(this); bool projectDefaultLazyIsTrue = ArchAngel.Interfaces.SharedData.CurrentProject.GetProjectDefaultLazy(); if (projectDefaultLazyIsTrue) { foreach (var entity in set.EntitySet.Entities.Where(e => e.GetEntityLazy() == Interfaces.NHibernateEnums.EntityLazyTypes.@false)) { foreach (var property in entity.Properties.Where(p => p.GetPropertyIsLazy())) { result.Issues.Add(new ValidationIssue(string.Format("Property [{0}.{1}] is Lazy, but the entity is not Lazy-load.", entity.Name, property.Name), entity, ValidationErrorLevel.Error)); } } } else { foreach (var entity in set.EntitySet.Entities.Where(e => e.GetEntityLazy() == Interfaces.NHibernateEnums.EntityLazyTypes.@false || e.GetEntityLazy() == Interfaces.NHibernateEnums.EntityLazyTypes.inherit_default)) { foreach (var property in entity.Properties.Where(p => p.GetPropertyIsLazy())) { result.Issues.Add(new ValidationIssue(string.Format("Property [{0}.{1}] is Lazy, but the entity is not Lazy-load.", entity.Name, property.Name), entity, ValidationErrorLevel.Error)); } } } return(result); }
private static void MapAllColumns(MappingSet set, ITable table, Entity entity) { for (int i = 0; i < table.Columns.Count; i++) { set.ChangeMappedColumnFor(entity.ConcreteProperties[i]).To(table.Columns[i]); } }
public void Setup() { mappingSet = new MappingSetImpl(); table1 = new Table("Table1"); var table2 = new Table("Table2"); mapping3 = new MappingImpl { FromTable = table2 }; refMapping1 = new TableReferenceMappingImpl { FromTable = table2, ToReference = new ReferenceImpl() }; mappingSet.AddMapping(new MappingImpl { FromTable = table1 }); mappingSet.AddMapping(new MappingImpl { FromTable = table1 }); mappingSet.AddMapping(mapping3); mappingSet.AddMapping(refMapping1); mappingSet.AddMapping(new TableReferenceMappingImpl { FromTable = table1, ToReference = new ReferenceImpl() }); }
public void DeleteProperty(Property property) { if (MappingSet != null) { MappingSet.RemoveMappingsContaining(property); } }
public IValidationResult Run(MappingSet set) { ValidationResult result = new ValidationResult(this); if (set.EntitySet == null) { result.Issues.Add(new ValidationIssue("No Entities are present in the Entity Model", set, ValidationErrorLevel.Warning)); return result; } if (set.EntitySet.IsEmpty) { result.Issues.Add(new ValidationIssue("No Entities are present in the Entity Model", set.EntitySet, ValidationErrorLevel.Warning)); return result; } var inheritedEntities = set.EntitySet.Entities.Where(e => e.Parent != null); //foreach (var childEntity in inheritedEntities) //{ // var parent = childEntity.Parent; // foreach (Property property in parent.Key.Properties.Distinct(p => p.Name)) // if (childEntity.ConcreteProperties.Any(p => p.Name == property.Name) == false && EntityImpl.DetermineInheritanceTypeWithParent(childEntity) != EntityImpl.InheritanceType.TablePerClassHierarchy) // result.Issues.Add(new ValidationIssue(string.Format("Key Property {0} is missing from child Entity named {1}", property.Name, childEntity.Name), childEntity, ValidationErrorLevel.Error)); //} return result; }
public void ApplyChanges(MappingSet mappingSet, EntityKey key) { // Create new Component var component = existingSpecToUse.CreateImplementedComponentFor(key.Parent, newComponentName); // Set mapped column on the new Component's properties. foreach(var pair in propertyMappings) { var newProperty = component.GetProperty(pair.Key); var oldProperty = key.Properties.FirstOrDefault(p => p.Name == pair.Value); if(oldProperty == null) { // Something went horribly wrong. We have a Property that has been mapped, // but it doesn't actually exist. I am chosing to ignore this here, but log it. log.ErrorFormat("Property {0} was mapped in the ConvertKeyToComponent wizard, but doesn't actually exist in the model.", pair.Value); continue; } newProperty.SetMappedColumn(oldProperty.MappedColumn()); } // Delete existing properties if needed. if(deleteExistingProperties) { foreach(var property in key.Properties.ToList()) { property.DeleteSelf(); } } key.Component = component; }
public void Setup() { mappingSet = new MappingSetImpl(new Database("DB1"), new EntitySetImpl()); entity1 = new EntityImpl("Entity1"); entity2 = new EntityImpl("Entity2"); mappingSet.EntitySet.AddEntity(entity1); mappingSet.EntitySet.AddEntity(entity2); reference1 = entity1.CreateReferenceTo(entity2); var reference2 = entity1.CreateReferenceTo(entity2); refMapping1 = new TableReferenceMappingImpl { FromTable = new Table("Table2"), ToReference = reference2 }; var refMapping2 = new TableReferenceMappingImpl { FromTable = new Table("Table1"), ToReference = reference1 }; relMapping1 = new RelationshipReferenceMappingImpl { FromRelationship = new RelationshipImpl(), ToReference = reference2 }; var relMapping2 = new RelationshipReferenceMappingImpl { FromRelationship = new RelationshipImpl(), ToReference = reference1 }; mappingSet.AddMapping(refMapping1); mappingSet.AddMapping(refMapping2); mappingSet.AddMapping(relMapping1); mappingSet.AddMapping(relMapping2); }
public void The_Correct_Entities_Are_Created() { MappingSet mappings = CreateMappingSet_OneTable(); EntitySet entities = mappings.EntitySet; IDatabase database = mappings.Database; ITable table = database.Tables[0]; Assert.That(entities.MappingSet, Is.SameAs(mappings)); Assert.That(mappings.Database, Is.SameAs(database)); Assert.That(entities, Is.Not.Null); Assert.That(entities, Has.Count(1)); Assert.That(entities[0].EntitySet, Is.SameAs(entities)); Assert.That(mappings.Mappings.Count, Is.EqualTo(1)); Mapping mapping = mappings.Mappings[0]; Assert.That(mapping.ToEntity, Is.SameAs(entities[0])); Assert.That(mapping.FromTable, Is.SameAs(table)); Assert.That(mapping.ToProperties.Count(), Is.EqualTo(2)); Assert.That(mapping.ToProperties[0], Is.SameAs(entities[0].Properties.ElementAt(0))); Assert.That(mapping.ToProperties[1], Is.SameAs(entities[0].Properties.ElementAt(1))); Assert.That(mapping.FromColumns.Count(), Is.EqualTo(2)); Assert.That(mapping.FromColumns[0], Is.SameAs(table.Columns[0])); Assert.That(mapping.FromColumns[1], Is.SameAs(table.Columns[1])); }
public void Delete() { if (MappingSet != null) { MappingSet.RemoveMapping(this); } }
private void PostProcessEntity(MappingSet set, Entity entity) { if (entity.HasParent == false) { return; } var childTable = entity.MappedTables().First(); var parentTable = entity.Parent.MappedTables().First(); // Create foreign key for parent relationship // This code makes a major assumption: That the primary key of the child has the same columns // as the primary key of the parent. var name = GetNextKeyName("FK_" + parentTable.Name + "_" + childTable.Name, set); var foreignKey = new Key(name, DatabaseKeyType.Foreign); var primaryKey = parentTable.FirstPrimaryKey; var childPrimaryKey = childTable.FirstPrimaryKey; foreignKey.ReferencedKey = primaryKey; childTable.AddKey(foreignKey); foreach (var column in childPrimaryKey.Columns) { foreignKey.AddColumn(column.Name); } }
public void SetUp() { mainPanel = MockRepository.GenerateStub <IMainPanel>(); form = MockRepository.GenerateMock <IEntityForm>(); ms = MockRepository.GenerateStub <MappingSet>(); Property property = new PropertyImpl("Prop1"); EntityKey key = new EntityKeyImpl(); entity = new EntityImpl("Entity1") { Key = key }; entity.AddProperty(property); key.AddProperty(property); mapping = new MappingImpl(); form.Stub(f => f.Mappings).Return(new List <Mapping> { mapping }); EntitySet es = new EntitySetImpl(); es.AddEntity(entity); ms.EntitySet = es; es.MappingSet = ms; ms.Stub(m => m.GetMappingsContaining(entity)).Return(new List <Mapping>()); var presenter = new EntityPresenter(mainPanel, form); presenter.AttachToModel(entity); }
public IValidationResult Run(MappingSet set) { ValidationResult result = new ValidationResult(this); if (set.EntitySet == null) { result.Issues.Add(new ValidationIssue("No Entities are present in the Entity Model", set, ValidationErrorLevel.Warning)); return(result); } if (set.EntitySet.IsEmpty) { result.Issues.Add(new ValidationIssue("No Entities are present in the Entity Model", set.EntitySet, ValidationErrorLevel.Warning)); return(result); } var inheritedEntities = set.EntitySet.Entities.Where(e => e.Parent != null && EntityImpl.DetermineInheritanceTypeWithParent(e) == EntityImpl.InheritanceType.TablePerClassHierarchy); foreach (var childEntity in inheritedEntities) { if (EntityImpl.DetermineInheritanceTypeWithParent(childEntity) == EntityImpl.InheritanceType.TablePerClassHierarchy && string.IsNullOrEmpty(childEntity.DiscriminatorValue)) { result.Issues.Add(new ValidationIssue(string.Format("Entity {0} is missing a discriminator-value (Table Per Hierarchy inheritance)", childEntity.Name), childEntity, ValidationErrorLevel.Error)); } } return(result); }
private static void MapAllColumns(MappingSet set, ITable table, Entity entity) { for(int i = 0; i < table.Columns.Count; i++) { set.ChangeMappedColumnFor(entity.ConcreteProperties[i]).To(table.Columns[i]); } }
public IFreeDocument MappingDocument(IFreeDocument doc) { if (doc == null) { return(null); } if (string.IsNullOrEmpty(MappingSet)) { return(doc); } var newdoc = new FreeDocument(); doc.DictCopyTo(newdoc); foreach (var item in MappingSet.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)) { var kv = item.Split(':'); if (kv.Length != 2) { continue; } if (kv[0] == kv[1]) { continue; } if (newdoc.Keys.Contains(kv[0])) { newdoc[kv[1]] = newdoc[kv[0]]; newdoc.Remove(kv[0]); } } return(newdoc); }
public void AddPropertyAndColumn(ComponentPropertyMarker prop, IColumn col) { if (FromTable == null) { FromTable = col.Parent; } if (ToComponent == null) { ToComponent = prop.Component; } if (col.Parent != FromTable) { throw new ArgumentException("Cannot add columns from multiple tables to a single Mapping object"); } if (prop.Component != ToComponent) { throw new ArgumentException("Cannot add properties from multiple components to a single Mapping object"); } properties.Add(prop); columns.Add(col); if (MappingSet != null) { MappingSet.InvalidateCache(); } RaisePropertyChanged("Mappings"); }
public void SetMapping(ComponentPropertyMarker property, IColumn column) { int index = properties.IndexOf(property); if (index == -1 && column != null) { AddPropertyAndColumn(property, column); return; } if (column == null) { properties.RemoveAt(index); columns.RemoveAt(index); if (MappingSet != null) { MappingSet.InvalidateCache(); } RaisePropertyChanged("Mappings"); return; } columns[index] = column; if (MappingSet != null) { MappingSet.InvalidateCache(); } RaisePropertyChanged("Mappings"); }
public IValidationResult Run(MappingSet set) { IValidationResult result = new ValidationResult(this); DatabaseProcessor proc = new DatabaseProcessor(); var mergeResults = proc.MergeDatabases(_realDatabase, set.Database); if (mergeResults.AnyChanges) { foreach (TableAdditionOperation tableOp in mergeResults.TableOperations.OfType <TableAdditionOperation>()) { // Additions show things that are in the generated database schema and not in the real one. result.Issues.Add(new ValidationIssue("Table exists in your NHibernate mapping files but not in your database", tableOp.Object, ValidationErrorLevel.Warning)); } foreach (ColumnAdditionOperation columnOp in mergeResults.ColumnOperations.OfType <ColumnAdditionOperation>()) { result.Issues.Add(new ValidationIssue("Column exists in your NHibernate mapping files but not in your database", columnOp.Object, ValidationErrorLevel.Warning)); } } return(result); }
public void SetUp() { entities = new EntitySetImpl(); entityParent = new EntityImpl("EntityParent"); entityParent.AddProperty(new PropertyImpl("PrimaryKey") { Type = "int", IsKeyProperty = true }); entityChild = new EntityImpl("EntityChild"); entityParent.AddChild(entityChild); entityChild.CopyPropertyFromParent(entityParent.ConcreteProperties[0]); entityChild.AddProperty(new PropertyImpl("ActualProperty") { Type = "string" }); entities.AddEntity(entityParent); entities.AddEntity(entityChild); var proc = new MappingProcessor(new OneToOneEntityProcessor()); mappingSet = proc.CreateOneToOneMapping(entities); }
public void SetUp() { entities = new EntitySetImpl(); entity1 = new EntityImpl("Entity1"); entity1.AddProperty(new PropertyImpl("PrimaryKey") { Type = "System.Int32", IsKeyProperty = true }); entity2 = new EntityImpl("Entity2"); entity2.AddProperty(new PropertyImpl("PrimaryKey") { Type = "System.Int32", IsKeyProperty = true }); entities.AddEntity(entity1); entities.AddEntity(entity2); reference = entity1.CreateReferenceTo(entity2); reference.Cardinality1 = Cardinality.Many; reference.Cardinality2 = Cardinality.Many; var proc = new MappingProcessor(new OneToOneEntityProcessor()); mappingSet = proc.CreateOneToOneMapping(entities); }
public IValidationResult Run(MappingSet set) { IValidationResult result = new ValidationResult(this); DatabaseProcessor proc = new DatabaseProcessor(); var mergeResults = proc.MergeDatabases(_realDatabase, set.Database); if (mergeResults.AnyChanges) { foreach (TableAdditionOperation tableOp in mergeResults.TableOperations.OfType<TableAdditionOperation>()) { // Additions show things that are in the generated database schema and not in the real one. result.Issues.Add(new ValidationIssue("Table exists in your NHibernate mapping files but not in your database", tableOp.Object, ValidationErrorLevel.Warning)); } foreach (ColumnAdditionOperation columnOp in mergeResults.ColumnOperations.OfType<ColumnAdditionOperation>()) { result.Issues.Add(new ValidationIssue("Column exists in your NHibernate mapping files but not in your database", columnOp.Object, ValidationErrorLevel.Warning)); } } return result; }
protected void SetupBase(string resourcePath) { loader = new EntityLoader(MockRepository.GenerateStub<IFileController>()); database = new Database("DB1"); table1 = new Table("Table1"); table1.AddColumn(new Column("ID") { Datatype = "int" }); table1.AddColumn(new Column("BasicClass2_Index") { Datatype = "int" }); database.AddEntity(table1); table2 = new Table("Table2"); table2.AddColumn(new Column("ID") { Datatype = "int" }); table2.AddColumn(new Column("BASIC_CLASS_1_ID")); database.AddEntity(table2); tableManyToMany = new Table("Class1Class2"); tableManyToMany.AddColumn(new Column("Class1ID") { Datatype = "int" }); tableManyToMany.AddColumn(new Column("Class2ID") { Datatype = "int" }); database.AddTable(tableManyToMany); relationship = table1.CreateRelationshipTo(table2); relationship.PrimaryKey.AddColumn("ID"); relationship.ForeignKey.AddColumn("BASIC_CLASS_1_ID"); // Call we are testing mappingSet = loader.GetEntities(new[] { Path.Combine("Resources", resourcePath) }, database); }
public IValidationResult Run(MappingSet set) { ValidationResult result = new ValidationResult(this); if (set.EntitySet == null) { result.Issues.Add(new ValidationIssue("No Entities are present in the Entity Model", set, ValidationErrorLevel.Warning)); return(result); } if (set.EntitySet.IsEmpty) { result.Issues.Add(new ValidationIssue("No Entities are present in the Entity Model", set.EntitySet, ValidationErrorLevel.Warning)); return(result); } var inheritedEntities = set.EntitySet.Entities.Where(e => e.Parent != null); //foreach (var childEntity in inheritedEntities) //{ // var parent = childEntity.Parent; // foreach (Property property in parent.Key.Properties.Distinct(p => p.Name)) // if (childEntity.ConcreteProperties.Any(p => p.Name == property.Name) == false && EntityImpl.DetermineInheritanceTypeWithParent(childEntity) != EntityImpl.InheritanceType.TablePerClassHierarchy) // result.Issues.Add(new ValidationIssue(string.Format("Key Property {0} is missing from child Entity named {1}", property.Name, childEntity.Name), childEntity, ValidationErrorLevel.Error)); //} return(result); }
public IValidationResult Run(MappingSet set) { IValidationResult result = new ValidationResult(this); foreach (var reference in set.EntitySet.Entities.SelectMany(e => e.References).Distinct()) { var mappedTable = reference.MappedTable(); if (reference.Cardinality1 == ArchAngel.Interfaces.Cardinality.Many && reference.Cardinality2 == ArchAngel.Interfaces.Cardinality.Many) { if (mappedTable == null) result.Issues.Add(new ValidationIssue(string.Format("Reference [{0} to {1}] with many-to-many collection type is missing an Association Table.", reference.Entity1.Name, reference.Entity2.Name), reference, ValidationErrorLevel.Error)); else { // Check that columns exist and match for the mapped table. var primaryTable1 = ArchAngel.NHibernateHelper.MappingFiles.Version_2_2.EntityMapper.GetPrimaryTable(reference.Entity1); var primaryTable2 = ArchAngel.NHibernateHelper.MappingFiles.Version_2_2.EntityMapper.GetPrimaryTable(reference.Entity2); if (mappedTable.Relationships.Where(t => t.PrimaryTable == primaryTable1).Count() == 0) result.Issues.Add(new ValidationIssue(string.Format("Reference [{0} to {1}] with many-to-many collection type is missing an Association Table.", reference.Entity1.Name, reference.Entity2.Name), reference, ValidationErrorLevel.Error)); if (mappedTable.Relationships.Where(t => t.PrimaryTable == primaryTable2).Count() == 0) result.Issues.Add(new ValidationIssue(string.Format("Reference [{0} to {1}] with many-to-many collection type is missing an Association Table.", reference.Entity1.Name, reference.Entity2.Name), reference, ValidationErrorLevel.Error)); } } else if (reference.MappedRelationship() == null && mappedTable == null) result.Issues.Add(new ValidationIssue(string.Format("Reference [{0} to {1}] is missing a Mapped Relationship or Association Table.", reference.Entity1.Name, reference.Entity2.Name), reference, ValidationErrorLevel.Error)); } foreach (var directedReference in set.EntitySet.Entities.SelectMany(e => e.DirectedReferences).Distinct()) { var collectionType = (ArchAngel.Interfaces.Scripting.NHibernate.Model.CollectionTypes)Enum.Parse(typeof(ArchAngel.Interfaces.Scripting.NHibernate.Model.CollectionTypes), NHCollections.GetAssociationType(directedReference).ToString(), true); if (collectionType == ArchAngel.Interfaces.Scripting.NHibernate.Model.CollectionTypes.Map || collectionType == ArchAngel.Interfaces.Scripting.NHibernate.Model.CollectionTypes.IDBag || collectionType == ArchAngel.Interfaces.Scripting.NHibernate.Model.CollectionTypes.List) { var indexColumn = NHCollections.GetIndexColumn(directedReference, ArchAngel.NHibernateHelper.MappingFiles.Version_2_2.EntityMapper.GetPrimaryTable(directedReference.ToEntity)); if (indexColumn == null) { result.Issues.Add(new ValidationIssue(string.Format("'{0}' collection [{1} to {2}] has an invalid index column specified.", collectionType.ToString(), directedReference.FromEntity.Name, directedReference.ToEntity.Name), directedReference.Reference, ValidationErrorLevel.Error)); } //newReference.CollectionIndexColumn = columnLookups[NHCollections.GetIndexColumn(directedReference, ArchAngel.NHibernateHelper.MappingFiles.Version_2_2.EntityMapper.GetPrimaryTable(directedReference.FromEntity))]; } //else if (collectionType == Interfaces.Scripting.NHibernate.Model.CollectionTypes.None && // directedReference.FromEndCardinality == ArchAngel.Interfaces.Cardinality.Many) //{ // result.Issues.Add(new ValidationIssue(string.Format("No collection type has been set for the reference between {1} and {2}.", // collectionType.ToString(), // directedReference.FromEntity.Name, // directedReference.ToEntity.Name), directedReference.Reference, ValidationErrorLevel.Error)); //} } return result; }
public FormCreateOneToOneMapping(MappingSet set) { InitializeComponent(); Set = set; SetAllTables(Set.Database.Tables); SetAlreadyMappedTables(Set.Mappings.Select(m => m.FromTable)); }
private static void SetupMappings(MappingSet set) { MapAllColumns(set, set.Database.Tables[0], set.EntitySet.Entities[0]); MapAllColumns(set, set.Database.Tables[1], set.EntitySet.Entities[1]); set.ChangeMappingFor(set.EntitySet.Entities[0].References[0]) .To(set.Database.Tables[0].Relationships[0]); }
public void ShouldAddMappingForGivenPropertyUsingLambdasAndReflection() { var mappingSet = new MappingSet<Foo>(); var mappingItemA = mappingSet.For(f => f.Name); var mappingItemB = mappingSet.For(typeof(Foo).GetProperty("Name", BindingFlags.Public | BindingFlags.Instance)); Assert.That(mappingItemA, Is.EqualTo(mappingItemB)); Assert.That(mappingSet.MappingItems.Count(), Is.EqualTo(1)); }
private static void SetupMappings(MappingSet set) { MapAllColumns(set, set.Database.Tables[0], set.EntitySet.Entities[0]); MapAllColumns(set, set.Database.Tables[1], set.EntitySet.Entities[1]); set.ChangeMappingFor(set.EntitySet.Entities[0].References[0]) .To(set.Database.Tables[0].Relationships[0]); }
private void TestAllMappings(MappingSet mappings, ITable table, Entity entity) { for (int i = 0; i < table.Columns.Count; i++) { Assert.That(mappings.GetMappedColumnFor(entity.Properties.ElementAt(i)), Is.SameAs(table.Columns[i])); Assert.That(mappings.GetMappedPropertiesFor(table.Columns.ElementAt(i)).ElementAt(0), Is.SameAs(entity.Properties.ElementAt(i))); } }
public void You_Should_Be_Able_To_Navigate_To_The_Mapped_Entities() { MappingSet ms = table.Database.MappingSet; var entitiesFor = ms.GetMappedEntitiesFor(table); Assert.That(entitiesFor.Count(), Is.EqualTo(1), "Wrong number of entities returned."); Assert.That(entitiesFor.ElementAt(0), Is.SameAs(entity)); }
private void ProcessEntity(MappingSet set, Entity entity) { var table = processor.CreateTable(entity); set.Database.AddTable(table); CreateMappingForNewTableAndEntity(entity, set, table); }
public void DeleteReference(Reference impl) { RemoveReference(impl); if (MappingSet != null) { MappingSet.DeleteReference(impl); } }
public void loadMappingSet(MappingSet mappingSet) { //first clear the existing mappings this.clear(); //then add the new mappingSet this.trees.Mappings = mappingSet.mappings; this.trees.ExpandAll(); }
public CreateOneToOneMappingPresenter(ICreateOneToOneMappingsForm form, IMainPanel mainPanel, MappingSet set) : base(mainPanel) { Form = form; Set = set; form.ChangesAccepted += (s, e) => AcceptChanges(); form.Cancelled += (s, e) => CancelChanges(); }
private void InitialiseMappingSet() { var mappingSet = new MappingSet(MappingSet.DefaultSet); mappingSet.InitialiseDefaultBindings(); _mappingSets.Clear(); _mappingSets.Add(mappingSet); }
/// <summary> /// Gets mappings for all entities of the current type originating in the current /// source system. /// </summary> /// <param name="mappingSet">The requested set.</param> /// <returns> /// The collection of mappings for all entities of the current type originating in /// the current source system. /// </returns> public IEnumerable <IMapping <TEntity> > GetMappings(MappingSet mappingSet) { return (this .mappingDataRepository .GetMappingData(mappingSet) .Select(mappingData => new Mapping(this, mappingData)) .ToArray()); }
public void ShoulApplyDefaultGeneratorToMappingItemFromProvidedGeneratorFactory() { var generatorFactory = MockRepository.GenerateStub<IProvideDefaultGenerators>(); var defaultGenerator = MockRepository.GenerateStub<IGenerateDummyData>(); generatorFactory.Stub(g => g.GetFor(Arg<PropertyInfo>.Is.Anything)).Return(defaultGenerator); var mappingSet = new MappingSet<Foo>(generatorFactory); var mappingItemA = mappingSet.DefaultFor(f => f.Name); Assert.That(mappingItemA.Generator, Is.EqualTo(defaultGenerator)); }
public IValidationResult Run(MappingSet set) { var result = new ValidationResult(this); foreach (var relationship in set.Database.Relationships.Where(r => r.PrimaryKey.Columns.Count != r.ForeignKey.Columns.Count)) { result.Issues.Add(new ValidationIssue(string.Format("Relationship between {0} and {1}: number of columns in primary key and foreign key don't match.", relationship.PrimaryTable.Name, relationship.ForeignTable.Name), relationship, ValidationErrorLevel.Error)); } return result; }
public void Setup() { mappingSet = ModelSetup.SetupModel(); entitySet = mappingSet.EntitySet; db = mappingSet.Database; table1 = db.Tables[0]; table2 = db.Tables[1]; table1.CreateRelationshipTo(table2); }
public void SetMappingSet(MappingSet newMappingSet) { RemoveEventSubscriptions(); if (newMappingSet == null) return; mappingSet = newMappingSet; MappingSetChanged.RaiseEvent(this); SetupEventSubscriptions(); }
public IValidationResult Run(MappingSet set) { IValidationResult result = new ValidationResult(this); foreach (Entity entity in set.EntitySet.Entities) foreach (var component in entity.Components) foreach (var prop in component.Properties.Where(p => p.MappedColumn() == null)) result.Issues.Add(new ValidationIssue(string.Format("Property [{0}] on Component [{1}] on Entity [{2}] is not mapped.", prop.PropertyName, component.Name, entity.Name), prop, ValidationErrorLevel.Error)); return result; }
public void ShouldSetDefaultGeneratorToAllStandardPropertiesFromDefaultGeneratorFactory() { var defaultGeneratorFactory = MockRepository.GenerateMock<IProvideDefaultGenerators>(); var generator = MockRepository.GenerateStub<IGenerateDummyData>(); defaultGeneratorFactory.Stub(f => f.GetFor(Arg<PropertyInfo>.Is.Anything)).Return(generator); var mappingSet = new MappingSet<Foo>(defaultGeneratorFactory); mappingSet.Defaults(); Assert.That(mappingSet.Items.Count(), Is.EqualTo(6)); }
public IValidationResult Run(MappingSet set) { IValidationResult result = new ValidationResult(this); var columns = set.Database.Tables.SelectMany(t => t.Columns); foreach (var column in columns) { if (column.OriginalDataType == null) result.Issues.Add(new ValidationIssue("Column does not have a Type", column, ValidationErrorLevel.Error)); } return result; }
public void Setup() { mappingSet = new MappingSetImpl(); entity1 = new EntityImpl("Entity1"); var entity2 = new EntityImpl("Entity2"); mapping3 = new MappingImpl { ToEntity = entity2 }; mappingSet.AddMapping(new MappingImpl { ToEntity = entity1 }); mappingSet.AddMapping(new MappingImpl { ToEntity = entity1 }); mappingSet.AddMapping(mapping3); }
public static void ProcessRelationshipInternal(MappingSet set, Relationship relationship, EntityProcessor processor) { Reference reference = processor.CreateReference(relationship, set.EntitySet); if (reference == null) return; RelationshipReferenceMapping mapping = new RelationshipReferenceMappingImpl(); mapping.FromRelationship = relationship; mapping.ToReference = reference; //set.EntitySet.AddReference(reference); set.AddMapping(mapping); }
public IValidationResult Run(MappingSet set) { var result = new ValidationResult(this); HashSet<string> names = new HashSet<string>(); foreach (var entity in set.EntitySet.Entities) { if (entity.PrimaryKeyColumns().Count == 0 && entity.MappedTables().Count() > 0) result.Issues.Add(new ValidationIssue(string.Format("Entity [{0}] has no columns in a primary key.", entity.Name), entity, ValidationErrorLevel.Error)); } return result; }
public void UsingDefaultsShouldNotOverridePresetGenerators() { var defaultGeneratorFactory = MockRepository.GenerateMock<IProvideDefaultGenerators>(); var preSetGenerator = MockRepository.GenerateStub<IGenerateDummyData>(); var generator = MockRepository.GenerateStub<IGenerateDummyData>(); defaultGeneratorFactory.Stub(f => f.GetFor(Arg<PropertyInfo>.Is.Anything)).Return(generator); var mappingSet = new MappingSet<Foo>(defaultGeneratorFactory); mappingSet.For(f=> f.Age).Use(preSetGenerator); mappingSet.Defaults(); Assert.That(mappingSet.Items.Any(i => i.Generator == preSetGenerator)); }
public IValidationResult Run(MappingSet set) { IValidationResult result = new ValidationResult(this); foreach (Entity entity in set.EntitySet.Entities) { foreach (var property in entity.Properties.Except(entity.ForeignKeyPropertiesToExclude)) { if (string.IsNullOrEmpty(property.Type)) result.Issues.Add(new ValidationIssue(string.Format("Property does not have a Type: {0}.{1}", property.Entity.Name, property.Name), property, ValidationErrorLevel.Error)); } } return result; }
public IValidationResult Run(MappingSet set) { var result = new ValidationResult(this); var properties = set.EntitySet.Entities.SelectMany(e => e.ConcreteProperties); foreach (var property in properties) { if (!property.Entity.IsAbstract && property.MappedColumn() == null) result.Issues.Add(new ValidationIssue(string.Format("Property {0} on Entity {1} has not been mapped.", property.Name, property.Entity.Name), property, ValidationErrorLevel.Warning)); } return result; }
public void Setup() { set = new MappingSetImpl(); entity = new EntityImpl("Entity1"); set.EntitySet.AddEntity(entity); table = new Table("Table1"); table.AddColumn(new Column("Street")); set.Database.AddTable(table); spec = new ComponentSpecificationImpl("Address"); spec.AddProperty(new ComponentPropertyImpl("Street")); set.EntitySet.AddComponentSpecification(spec); component = spec.CreateImplementedComponentFor(entity, "HomeAddress"); set.ChangeMappingFor(component.Properties[0]).To(table.Columns[0]); }
public IValidationResult Run(MappingSet set) { IValidationResult result = new ValidationResult(this); foreach (var componentSpec in set.EntitySet.ComponentSpecifications) { var properties = componentSpec.Properties;// set.EntitySet.ComponentSpecifications.SelectMany(e => e.Properties); foreach (var property in properties) { if (string.IsNullOrEmpty(property.Type)) result.Issues.Add(new ValidationIssue(string.Format("Component Property does not have a Type: {0}.{1}", componentSpec.Name, property.Name), property, ValidationErrorLevel.Error)); } } return result; }
public IValidationResult Run(MappingSet set) { var result = new ValidationResult(this); HashSet<string> names = new HashSet<string>(); foreach (var entity in set.EntitySet.Entities) { foreach (var child in entity.Children) { if (entity.DirectedReferences.Count(d => d.ToEntity == child) > 0) result.Issues.Add(new ValidationIssue(string.Format("Entity [{0}] references a child entity (inheritance): [{1}]. Remove the reference.", entity.Name, child.Name), entity, ValidationErrorLevel.Error)); } } return result; }
public IValidationResult Run(MappingSet set) { IValidationResult result = new ValidationResult(this); bool projectDefaultLazyIsTrue = ArchAngel.Interfaces.SharedData.CurrentProject.GetProjectDefaultLazy(); if (projectDefaultLazyIsTrue) foreach (var entity in set.EntitySet.Entities.Where(e => e.GetEntityLazy() == Interfaces.NHibernateEnums.EntityLazyTypes.@false)) foreach (var property in entity.Properties.Where(p => p.GetPropertyIsLazy())) result.Issues.Add(new ValidationIssue(string.Format("Property [{0}.{1}] is Lazy, but the entity is not Lazy-load.", entity.Name, property.Name), entity, ValidationErrorLevel.Error)); else foreach (var entity in set.EntitySet.Entities.Where(e => e.GetEntityLazy() == Interfaces.NHibernateEnums.EntityLazyTypes.@false || e.GetEntityLazy() == Interfaces.NHibernateEnums.EntityLazyTypes.inherit_default)) foreach (var property in entity.Properties.Where(p => p.GetPropertyIsLazy())) result.Issues.Add(new ValidationIssue(string.Format("Property [{0}.{1}] is Lazy, but the entity is not Lazy-load.", entity.Name, property.Name), entity, ValidationErrorLevel.Error)); return result; }
/// ------------------------------------------------------------------------------------ /// <summary> /// Initializes a new instance of the <see cref="SCTextEnum"/> class. /// </summary> /// <param name="settings">The import settings</param> /// <param name="domain">The source domain</param> /// <param name="startRef">first reference to retrieve</param> /// <param name="endRef">last reference to retrieve</param> /// <param name="encConverters">The encoding converters repository</param> /// ------------------------------------------------------------------------------------ public SCTextEnum(IScrImportSet settings, ImportDomain domain, BCVRef startRef, BCVRef endRef, IEncConverters encConverters) { m_settings = settings; m_domain = domain; m_startRef = new BCVRef(startRef); m_endRef = new BCVRef(endRef); m_mappingSet = m_settings.GetMappingSetForDomain(domain); // Gets the set of encoding converters m_encConverters = encConverters; // make a list of all of the begin and end markers for inline markers // Also build the map of encoding converters m_InlineBeginAndEndMarkers = new List<string>(); foreach (ImportMappingInfo mapping in m_settings.GetMappingListForDomain(domain)) { if (mapping.IsInline || m_settings.ImportTypeEnum == TypeOfImport.Paratext5) { m_InlineBeginAndEndMarkers.Add(mapping.BeginMarker); if (mapping.IsInline) m_InlineBeginAndEndMarkers.Add(mapping.EndMarker); } } m_InlineBeginAndEndMarkers.Sort(new StrLengthComparer(false)); // Build a list of all of the characters that inline markers start with Set<char> tempCharList = new Set<char>(); foreach (string marker in m_InlineBeginAndEndMarkers) tempCharList.Add(marker[0]); // Set ignores duplicates. m_InlineMarkerStartChars = tempCharList.ToArray(); // Get the import file source that will provide the files to import. m_importSource = settings.GetImportFiles(domain); m_importSourceEnum = m_importSource.GetEnumerator(); }
public void SetUp() { mainPanel = MockRepository.GenerateStub<IMainPanel>(); form = MockRepository.GenerateMock<IEntityForm>(); ms = MockRepository.GenerateStub<MappingSet>(); Property property = new PropertyImpl("Prop1"); EntityKey key = new EntityKeyImpl(); entity = new EntityImpl("Entity1") { Key = key }; entity.AddProperty(property); key.AddProperty(property); mapping = new MappingImpl(); form.Stub(f => f.Mappings).Return(new List<Mapping> { mapping }); EntitySet es = new EntitySetImpl(); es.AddEntity(entity); ms.EntitySet = es; es.MappingSet = ms; ms.Stub(m => m.GetMappingsContaining(entity)).Return(new List<Mapping>()); var presenter = new EntityPresenter(mainPanel, form); presenter.AttachToModel(entity); }
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; }
/// ------------------------------------------------------------------------------------ /// <summary> /// This method gets all the mappings from the ScrImportSet and loads them into a /// list view so the user can modify them if necessary. /// </summary> /// <param name="lv">The list view to add mappings to</param> /// <param name="mappingSet">The set of mappings to add</param> /// ------------------------------------------------------------------------------------ protected void LoadMappingsFromSettings(FwListView lv, MappingSet mappingSet) { // REVIEW DavidO: I think we want to be smarter about whether or not to clear the // list view. We wouldn't necessarily want to clear the list if the user has // already been to this step and is coming back to it without having changed any // previous wizard step choices. lv.Items.Clear(); foreach (ImportMappingInfo mapping in m_settings.Mappings(mappingSet)) { // Omit the \id marker if (mapping.BeginMarker != ScriptureServices.kMarkerBook && (mapping.IsInUse || m_fShowAllMappings)) { LoadLVMappingItem(lv, mapping); } } if (lv.Items.Count > 0) { lv.Items[0].Selected = true; lv.Items[0].Focused = true; } }