/// <inheritdoc/> /// <exception cref="ValidationException">Validations errors.</exception> protected override void ValidateState() { using (var ea = new ExceptionAggregator()) { ea.Execute(base.ValidateState); if (PrimaryKey == null) { ea.Execute(() => { throw new ValidationException(Strings.ExUndefinedPrimaryKey, Path); }); } var pkTypes = PrimaryKey.KeyColumns.Select(c => c.Value.Type); var fkTypes = ForeignKeyColumns.Select(c => c.Value.Type); if (pkTypes.Count() != pkTypes.Zip(fkTypes).Where(p => p.First.Type == p.Second.Type.StripNullable()).Count()) { ea.Execute(() => { throw new ValidationException( Strings.ExInvalidForeignKeyStructure, Path); }); } ea.Complete(); } }
/// <summary> /// Add foreign key /// </summary> /// <param name="ForeignKeyTable">Table of the foreign key</param> /// <param name="ForeignKeyColumn">Column of the foreign key</param> public void AddForeignKey(string ForeignKeyTable, string ForeignKeyColumn) { if (string.IsNullOrEmpty(ForeignKeyTable) || string.IsNullOrEmpty(ForeignKeyColumn)) { return; } ForeignKeyColumns.Add(ForeignKeyColumn); ForeignKeyTables.Add(ForeignKeyTable); }
public virtual void Initialize() { Schemas.ForEach(s => s.Initialize(Tables)); Tables.ForEach(t => t.Initialize(Schemas, Columns, PrimaryKeys, ForeignKeys, CheckConstraints)); Columns.ForEach(c => c.Initialize(Tables)); PrimaryKeys.ForEach(k => k.Initialize(Tables, PrimaryKeyColumns)); PrimaryKeyColumns.ForEach(c => c.Initialize(PrimaryKeys, Tables, Columns)); ForeignKeys.ForEach(k => k.Initialize(Tables, ForeignKeyColumns)); ForeignKeyColumns.ForEach(c => c.Initialize(ForeignKeys, Tables, Columns)); CheckConstraints.ForEach(c => c.Initialize(Tables)); }
/// <summary> /// Copies this instance /// </summary> /// <param name="parentTable">The new parent table.</param> /// <returns>The copy</returns> public IColumn Copy(ITable parentTable) { return(new Column <T>(Name, DataType, Length, Nullable, AutoIncrement, Index, PrimaryKey, Unique, string.Empty, string.Empty, Default.To <T>(), ComputedColumnSpecification, OnDeleteCascade, OnUpdateCascade, OnDeleteSetNull, parentTable) { ForeignKeyColumns = ForeignKeyColumns.ToList(), ForeignKeyTables = ForeignKeyTables.ToList() }); }
/// <summary> /// Determines whether the specified <see cref="System.Object"/>, is equal to this instance. /// </summary> /// <param name="obj">The <see cref="System.Object"/> to compare with this instance.</param> /// <returns> /// <c>true</c> if the specified <see cref="System.Object"/> is equal to this instance; /// otherwise, <c>false</c>. /// </returns> public override bool Equals(object obj) { return((obj is Column <T> Item) && AutoIncrement == Item.AutoIncrement && ComputedColumnSpecification == Item.ComputedColumnSpecification && DataType == Item.DataType && Default == Item.Default && ForeignKeyColumns.All(x => Item.ForeignKeyColumns.Contains(x)) && ForeignKeyTables.All(x => Item.ForeignKeyTables.Contains(x)) && Index == Item.Index && Length == Item.Length && Name == Item.Name && Nullable == Item.Nullable && OnDeleteCascade == Item.OnDeleteCascade && OnDeleteSetNull == Item.OnDeleteSetNull && OnUpdateCascade == Item.OnUpdateCascade && PrimaryKey == Item.PrimaryKey && Unique == Item.Unique && ParentTable.Name == Item.ParentTable.Name); }