public void CreateForeignKeyOfEntity(string entityName) { if (!HasFormula && !"none".Equals(ForeignKeyName, StringComparison.InvariantCultureIgnoreCase)) { ForeignKey fk = table.CreateForeignKey(ForeignKeyName, ConstraintColumns, entityName); fk.CascadeDeleteEnabled = cascadeDeleteEnabled; } }
public override void CreateForeignKeyOfEntity(string entityName) { if (!HasFormula && !string.Equals("none", ForeignKeyName, StringComparison.InvariantCultureIgnoreCase)) { var referencedColumns = new List <Column>(_prototype.ColumnSpan); foreach (Column column in _prototype.ColumnIterator) { referencedColumns.Add(column); } ForeignKey fk = Table.CreateForeignKey(ForeignKeyName, ConstraintColumns, entityName, referencedColumns); fk.CascadeDeleteEnabled = IsCascadeDeleteEnabled; } }
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 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.OrdinalIgnoreCase)) { IEnumerable <Column> ce = new SafetyEnumerable <Column>(property.ColumnIterator); // NH : Ensure that related columns have same length ForeignKey.AlignColumns(ConstraintColumns, ce); ForeignKey fk = Table.CreateForeignKey(ForeignKeyName, ConstraintColumns, ((EntityType)Type).GetAssociatedEntityName(), ce); fk.CascadeDeleteEnabled = IsCascadeDeleteEnabled; } } }
/// <summary> /// /// </summary> /// <param name="persistentClass"></param> public void CreateForeignKeyOfClass(System.Type persistentClass) { table.CreateForeignKey(ForeignKeyName, ConstraintColumns, persistentClass); }