public bool Equals(ReferenceImpl other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Equals(other.entity1, entity1) && Equals(other.entity2, entity2) && Equals(other.end2Name, end2Name) && Equals(other.end1Name, end1Name) && Equals(other.MappedRelationship(), this.MappedRelationship())); }
public Reference DeserialiseReference(XmlNode refNode, EntitySet set) { Reference reference = new ReferenceImpl(); NodeProcessor processor = new NodeProcessor(refNode); reference.Identifier = processor.Attributes.GetGuid("identifier"); reference.End1Name = processor.GetString("End1Name"); reference.End2Name = processor.GetString("End2Name"); reference.End1Enabled = processor.GetBool("End1Enabled"); reference.End2Enabled = processor.GetBool("End2Enabled"); reference.Entity1 = set.GetEntity(processor.GetString("Entity1")); reference.Entity2 = set.GetEntity(processor.GetString("Entity2")); reference.Cardinality1 = DeserialiseCardinality(refNode.SelectSingleNode("Cardinality1")); reference.Cardinality2 = DeserialiseCardinality(refNode.SelectSingleNode("Cardinality2")); if (Version >= 2) { reference.IncludeForeignKey = processor.GetBool("IncludeForeignKey"); } ProcessScriptBase(reference, refNode); // Fixup virtual properties of type PropertiesForThisEntity foreach (var uo in reference.Ex.Where(v => v.DataType == TypePropertiesForThisEntity)) { object obj = null; if (reference.Entity1 != null) { obj = reference.Entity1.Properties.SingleOrDefault(p => p.Name.Equals(uo.Value.ToString(), StringComparison.InvariantCultureIgnoreCase)); } if (obj == null && reference.Entity2 != null) { obj = reference.Entity2.Properties.SingleOrDefault(p => p.Name.Equals(uo.Value.ToString(), StringComparison.InvariantCultureIgnoreCase)); } uo.Value = obj; } return(reference); }
public Reference CreateReferenceTo(Entity entity2) { var newRel = new ReferenceImpl(); newRel.Entity1 = this; newRel.Entity2 = entity2; newRel.End1Name = entity2.Name; newRel.End2Name = Name; AddReference(newRel); if (EntitySet != null) { EntitySet.AddReference(newRel); } if (entity2 != this) { entity2.AddReference(newRel); } return(newRel); }
public static void CreateNewReference(Entity theEntity) { List<Entity> unavailableEntities = new List<Entity>(); foreach (ReferenceImpl reference in theEntity.References) { if (reference.Entity1 == theEntity) unavailableEntities.Add(reference.Entity2); else if (reference.Entity2 == theEntity) unavailableEntities.Add(reference.Entity1); } UserControls.FormSelectExistingEntity form = new UserControls.FormSelectExistingEntity(theEntity, unavailableEntities, null, "Select entity to reference", false, UserControls.FormSelectExistingEntity.RequestorTypes.Entity_Select_Existing); form.ShowDialog(); if (form.SelectedEntity != null) { Entity selectedEntity = form.SelectedEntity; ReferenceImpl newReference = new ReferenceImpl(theEntity, selectedEntity); newReference.Name = "New Reference"; newReference.EntitySet = selectedEntity.EntitySet; newReference.Cardinality1 = form.CardinalityPrimary; newReference.Cardinality2 = form.CardinalityForeign; newReference.End1Name = newReference.Cardinality1 == ArchAngel.Interfaces.Cardinality.Many ? newReference.Entity2.Name.Pluralize() : newReference.Entity2.Name; newReference.End2Name = newReference.Cardinality2 == ArchAngel.Interfaces.Cardinality.Many ? newReference.Entity1.Name.Pluralize() : newReference.Entity1.Name; newReference.End1Enabled = true; newReference.End2Enabled = true; theEntity.AddReference(newReference); selectedEntity.AddReference(newReference); if (form.SelectedRelationship != null) newReference.SetMappedRelationship(form.SelectedRelationship); else if (form.AssociationTable != null) newReference.SetMappedTable(form.AssociationTable); else if (selectedEntity.MappedTables().Count() == 1) newReference.SetMappedTable(selectedEntity.MappedTables().ElementAt(0)); theEntity.EntitySet.AddReference(newReference); } }
private void ProcessMouseOverEndOfLine(ReferenceImpl reference, MouseEventArgs e, Rectangle endRectangle, bool isEnd1) { RefEditorForm.Visible = false; int offset = 0; Point pt = new Point(endRectangle.X, endRectangle.Y + endRectangle.Height);// PointToClient(Cursor.Position);// e.Location; pt.Offset(offset, offset); if (endRectangle != CurrentEndRectangle || !RefEditorForm.Visible) { CurrentEndRectangle = endRectangle; RefEditorForm.Fill(reference, isEnd1); //RefEditorForm.Fill((ReferenceImpl)lineEndWithFocus.Line.DataObject, lineEndWithFocus.EndType == ShapeCanvas.LineEndWithFocus.EndTypes.Start); if (pt.X + RefEditorForm.Width < this.Width) RefEditorForm.Location = pt; else { pt.Offset(-1 * RefEditorForm.Width + endRectangle.Width + offset * 2, 0); RefEditorForm.Location = pt; } if (pt.Y + RefEditorForm.Height - ScrollPosition.Y < this.Height) { pt.Offset(0, -1 * ScrollPosition.Y); RefEditorForm.Location = pt; } else { //pt.Offset(0, -1 * RefEditorForm.Height - endRectangle.Height + offset * 2); pt.Y = this.Height - RefEditorForm.Height - 2; RefEditorForm.Location = pt; } RefEditorForm.Visible = true; RefEditorForm.Refresh(); } }
public void Correct_References_Are_Created() { EntityProcessor proc = MockRepository.GenerateMock<EntityProcessor>(); Entity entity1 = new EntityImpl(); Entity entity2 = new EntityImpl(); Reference reference = new ReferenceImpl(entity1, entity2); proc.Stub(p => p.CreateEntity(Table1)).Return(entity1); proc.Stub(p => p.CreateEntity(Table2)).Return(entity2); proc.Stub(p => p.CreateReference(Relationship12, Set.EntitySet)).Return(reference); MappingProcessor mappingProc = new MappingProcessor(proc); mappingProc.CreateOneToOneMappingsFor(new[] { Table1, Table2 }, Set); proc.AssertWasCalled(p => p.CreateEntity(Table1)); proc.AssertWasCalled(p => p.CreateEntity(Table2)); proc.AssertWasCalled(p => p.CreateReference(Relationship12, Set.EntitySet)); proc.AssertWasNotCalled(p => p.CreateReference(Relationship13, Set.EntitySet)); }
public bool Equals(ReferenceImpl other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return Equals(other.entity1, entity1) && Equals(other.entity2, entity2) && Equals(other.end2Name, end2Name) && Equals(other.end1Name, end1Name) && Equals(other.MappedRelationship(), this.MappedRelationship()); }
public Reference CreateReferenceTo(Entity entity2) { var newRel = new ReferenceImpl(); newRel.Entity1 = this; newRel.Entity2 = entity2; newRel.End1Name = entity2.Name; newRel.End2Name = Name; AddReference(newRel); if (EntitySet != null) EntitySet.AddReference(newRel); if (entity2 != this) entity2.AddReference(newRel); return newRel; }
public void It_Returns_The_Reference_Objects() { ProviderInfo info = new ProviderInfo(); var entity1 = new EntityImpl("T1"); var entity2 = new EntityImpl("T2"); var entity3 = new EntityImpl("T3"); var rel1 = new ReferenceImpl { EntitySet = info.MappingSet.EntitySet }; var rel2 = new ReferenceImpl { EntitySet = info.MappingSet.EntitySet }; info.MappingSet.EntitySet.AddEntity(entity1); info.MappingSet.EntitySet.AddEntity(entity2); info.MappingSet.EntitySet.AddEntity(entity3); rel1.AddThisTo(entity1, entity2); rel2.AddThisTo(entity3, entity2); IEnumerable<IScriptBaseObject> objects = info.GetAllObjectsOfType(typeof(Reference)); Assert.That(objects, Has.Length(2)); Assert.That(objects.Contains(rel1)); Assert.That(objects.Contains(rel2)); }
public static Reference GetReference() { Reference reference = new ReferenceImpl(); var mappingSet = new MappingSetImpl(); var entitySet = new EntitySetImpl(); entitySet.AddReference(reference); mappingSet.EntitySet = entitySet; return reference; }
private void UseDiscoveredInformationToCreateReferences(MappingSet mappingSet) { while (associationInformation.Count > 0) { var info = associationInformation[0]; associationInformation.RemoveAt(0); // Get existing objects var fromEntity = mappingSet.EntitySet.GetEntity(info.ThisEntityName); var fromTable = fromEntity.MappedTables().First(); var toEntity = mappingSet.EntitySet.GetEntity(info.OtherEntityName); var toTable = toEntity.MappedTables().First(); // Sort out this side of the reference. Reference reference = new ReferenceImpl(); reference.Entity1 = fromEntity; reference.End1Name = info.PropertyName; reference.End1Enabled = true; reference.Cardinality1 = info.Cardinality; reference.SetEnd1AssociationType(info.AssociationType); reference.SetEnd1IndexColumnName(info.IndexColumn); reference.SetEnd1SqlWhereClause(info.WhereClause); reference.SetReferenceEnd1FetchMode(info.FetchMode); reference.SetReferenceEnd1CollectionFetchMode(info.CollectionFetchMode); reference.SetReferenceEnd1Insert(info.Insert); reference.SetReferenceEnd1Update(info.Update); reference.SetReferenceEnd1Inverse(info.Inverse); reference.SetReferenceEnd1FetchMode(info.FetchMode); reference.SetReferenceEnd1Lazy(info.CollectionLazy); reference.SetReferenceEnd1Cascade(info.Cascade); reference.SetReferenceEnd1CollectionCascade(info.CollectionCascade); if (!string.IsNullOrWhiteSpace(info.OrderByColumnName)) { var orderByProp = fromEntity.Properties.SingleOrDefault(p => p.MappedColumn() != null && p.MappedColumn().Name.Equals(info.OrderByColumnName, StringComparison.InvariantCultureIgnoreCase)); if (orderByProp != null) reference.SetReferenceEnd1OrderByProperty(orderByProp.Name); } reference.SetReferenceEnd1OrderByIsAsc(info.OrderByIsAsc); // Find the other side of the reference. ProcessOtherEndOfReference(info, toEntity, reference); //associationInformation.RemoveAt(0); fromEntity.AddReference(reference); if (fromEntity.InternalIdentifier != toEntity.InternalIdentifier) toEntity.AddReference(reference); if (info.AssociationTableName != null && !string.IsNullOrEmpty(info.AssociationTableName.TableName)) { // Map Reference to Table string schema = /*string.IsNullOrEmpty(info.AssociationTableName.SchemaName) ? "" :*/ info.AssociationTableName.SchemaName.UnBackTick(); var mappedTable = mappingSet.Database.GetTable(info.AssociationTableName.TableName.UnBackTick(), schema); if (mappedTable == null) throw new NHibernateMappingException(string.Format("Could not find association table {0} to map to reference {1}.", info.AssociationTableName, reference.Name)); mappingSet.ChangeMappingFor(reference).To(mappedTable); } else { IEnumerable<IColumn> foreignKeyColumns; Func<DirectedRelationship, bool> predicate; if (info.ForeignKeyColumnNames.Count == 0 && info.Cardinality.Start == 1 && info.Cardinality.End == 1 && fromTable != toTable) { predicate = r => r.ToKey.Columns.OrderBy(c => c.Name).SequenceEqual(r.ToTable.ColumnsInPrimaryKey.OrderBy(c => c.Name)) && r.FromKey.Columns.OrderBy(c => c.Name).SequenceEqual(r.FromTable.ColumnsInPrimaryKey.OrderBy(c => c.Name)); } else { if (info.ForeignKeyBelongsToThisTable) { foreignKeyColumns = info.ForeignKeyColumnNames.Select(f => fromTable.GetColumn(f.UnBackTick())); if (fromTable == toTable) { // Self referencing keys might have the primary key at either end. predicate = r => (r.FromKey.Columns.SequenceEqual(foreignKeyColumns) || r.ToKey.Columns.SequenceEqual(foreignKeyColumns)); } else predicate = r => r.FromKey.Columns.SequenceEqual(foreignKeyColumns); } else { foreignKeyColumns = info.ForeignKeyColumnNames.Select(f => toTable.GetColumn(f.UnBackTick())); predicate = r => r.ToKey.Columns.SequenceEqual(foreignKeyColumns); } } var possibleRelationships = fromTable.DirectedRelationships.Where(r => r.ToTable == toTable); var relationshipToMap = possibleRelationships.FirstOrDefault(predicate); if (relationshipToMap != null) mappingSet.ChangeMappingFor(reference).To(relationshipToMap.Relationship); else throw new NHibernateMappingException(string.Format("Could not find relationship to map to for reference between Entities \"{0}\" and \"{1}\"", info.ThisEntityName, info.OtherEntityName)); } } }
public void A_FromCardinality__It_Should_Default_To_One() { string expectedXML = string.Format(CardinalityFormatXml, 3, 4, 1, 1); Reference reference = new ReferenceImpl (new Guid("11111111-1111-1111-1111-111111111111")) { Entity2 = new EntityImpl("Entity1"), Entity1 = new EntityImpl("Entity2"), Cardinality1 = new Cardinality(3, 4), End1Enabled = true, End2Enabled = true, End1Name = "ParentEntity1", End2Name = "Entity2s" }; string outputXML = new EntitySetSerialisationScheme().SerialiseReference(reference); outputXML = XmlSqueezer.RemoveWhitespaceBetweenElements(outputXML); Assert.That(outputXML, Is.EqualTo(expectedXML)); }
public void It_Should_Throw_An_Exception() { Reference reference = new ReferenceImpl(); new EntitySetSerialisationScheme().SerialiseReference(reference); }
public void A_ToEntity__It_Should_Throw_An_Exception() { Reference reference = new ReferenceImpl(); reference.Entity1 = new EntityImpl("Entity1"); new EntitySetSerialisationScheme().SerialiseReference(reference); }