public void CreatePropertyRefConstraints(IDictionary <string, PersistentClass> persistentClasses) { if (!string.IsNullOrEmpty(referencedPropertyName)) { if (string.IsNullOrEmpty(ReferencedEntityName)) { throw new MappingException( string.Format("ReferencedEntityName not specified for property '{0}' on entity {1}", ReferencedPropertyName, this)); } PersistentClass pc; persistentClasses.TryGetValue(ReferencedEntityName, out pc); if (pc == null) { throw new MappingException(string.Format("Could not find referenced entity '{0}' on {1}", ReferencedEntityName, this)); } Property property = pc.GetReferencedProperty(ReferencedPropertyName); if (property == null) { throw new MappingException("Could not find property " + ReferencedPropertyName + " on " + ReferencedEntityName); } if (!HasFormula && !"none".Equals(ForeignKeyName, StringComparison.InvariantCultureIgnoreCase)) { IEnumerable <Column> ce = new SafetyEnumerable <Column>(property.ColumnIterator); // NH : The four lines below was added to ensure that related columns have same length, // like ForeignKey.AlignColumns() do using (var fkCols = ConstraintColumns.GetEnumerator()) using (var pkCols = ce.GetEnumerator()) { while (fkCols.MoveNext() && pkCols.MoveNext()) { fkCols.Current.Length = pkCols.Current.Length; } } ForeignKey fk = Table.CreateForeignKey(ForeignKeyName, ConstraintColumns, ((EntityType)Type).GetAssociatedEntityName(), ce); fk.CascadeDeleteEnabled = IsCascadeDeleteEnabled; } } }
public Constraint() : base(ObjectType1.Constraint) { Columns = new ConstraintColumns(); Index = new Index(); }