public bool Equals(SchemaNamedElement other) { if (ReferenceEquals(null, other)) { return(false); } if (ReferenceEquals(this, other)) { return(true); } return(Equals(other.Name, Name)); }
public bool Equals(SchemaNamedElement other) { if (ReferenceEquals(null, other)) return false; if (ReferenceEquals(this, other)) return true; return Equals(other.Name, Name); }
private static List<KeySchema> GetKeys(SqlConnection con, SchemaNamedElement eTable) { var keys = new List<KeySchema>(); var aHash = new Dictionary<string, bool>(); string[] restrict3 = {null, null, null}; string[] restrict4 = {null, null, null, null}; #region Primary keys restrict3[0] = null; restrict3[1] = null; restrict3[2] = eTable.Name; var dtShema = SqlSchemaFactory.GetSchema(con, "PrimaryKeys", restrict3); aHash.Clear(); for (var x = 0; x < dtShema.Rows.Count; x++) { var cRow = dtShema.Rows[x]; var cName = cRow["CONSTRAINT_NAME"].ToString(); if (aHash.ContainsKey(cName)) continue; aHash.Add(cName, true); var eKey = new KeySchema { KeyType = ConstraintType.KeyPrimary, Name = cName, Clustered = Convert.ToBoolean(cRow["IS_CLUSTERED"], CultureInfo.InvariantCulture) }; var columns = new StringBuilder(); var dtv = dtShema.DefaultView; dtv.RowFilter = string.Format("CONSTRAINT_NAME = '{0}'", cName); dtv.Sort = "ORDINAL_POSITION ASC"; for (var y = 0; y < dtv.Count; y++) { columns.Append(dtv[y]["COLUMN_NAME"]); columns.Append(y == dtv.Count - 1 ? string.Empty : ", "); } eKey.Columns = columns.ToString(); keys.Add(eKey); } #endregion #region Foreign keys restrict4[0] = null; restrict4[1] = null; restrict4[2] = eTable.Name; restrict4[3] = null; dtShema = SqlSchemaFactory.GetSchema(con, "ForeignKeys", restrict4); aHash.Clear(); for (var x = 0; x < dtShema.Rows.Count; x++) { var cRow = dtShema.Rows[x]; if (Convert.ToBoolean(cRow["IS_DISABLED"], CultureInfo.InvariantCulture)) continue; var cName = cRow["CONSTRAINT_NAME"].ToString(); if (aHash.ContainsKey(cName)) continue; aHash.Add(cName, true); var eKey = new KeySchema { KeyType = ConstraintType.KeyForeign, Name = cName, RelTable = cRow["PK_TABLE_NAME"].ToString(), UpdateRule = GetDbsmRule(cRow["UPDATE_RULE"].ToString()), DeleteRule = GetDbsmRule(cRow["DELETE_RULE"].ToString()) }; var fcolumns = new StringBuilder(); var rcolumns = new StringBuilder(); var dtv = dtShema.DefaultView; dtv.RowFilter = string.Format("CONSTRAINT_NAME = '{0}'", cName); dtv.Sort = "ORDINAL_POSITION ASC"; for (var y = 0; y < dtv.Count; y++) { fcolumns.Append(dtv[y]["FK_COLUMN_NAME"]); fcolumns.Append(y == dtv.Count - 1 ? string.Empty : ", "); rcolumns.Append(dtv[y]["PK_COLUMN_NAME"]); rcolumns.Append(y == dtv.Count - 1 ? string.Empty : ", "); } eKey.Columns = fcolumns.ToString(); eKey.RelColumns = rcolumns.ToString(); keys.Add(eKey); } #endregion #region Checks restrict3[0] = null; restrict3[1] = null; restrict3[2] = eTable.Name; dtShema = SqlSchemaFactory.GetSchema(con, "CheckConstraints", restrict3); for (var x = 0; x < dtShema.Rows.Count; x++) { var row = dtShema.Rows[x]; var eKey = new KeySchema { KeyType = ConstraintType.Check, Name = row["CONSTRAINT_NAME"].ToString(), Source = row["SOURCE"].ToString() }; keys.Add(eKey); } #endregion #region Unique restrict3[0] = null; restrict3[1] = null; restrict3[2] = eTable.Name; dtShema = SqlSchemaFactory.GetSchema(con, "UniqueKeys", restrict3); aHash.Clear(); for (var x = 0; x < dtShema.Rows.Count; x++) { var cRow = dtShema.Rows[x]; var cName = cRow["CONSTRAINT_NAME"].ToString(); if (aHash.ContainsKey(cName)) continue; var eKey = new KeySchema(); aHash.Add(cName, true); eKey.KeyType = ConstraintType.Unique; eKey.Name = cName; var columns = new StringBuilder(); var dtv = dtShema.DefaultView; dtv.RowFilter = "CONSTRAINT_NAME = '" + cName + "'"; dtv.Sort = "ORDINAL_POSITION ASC"; for (var y = 0; y < dtv.Count; y++) { columns.Append(dtv[y]["COLUMN_NAME"]); columns.Append(y == dtv.Count - 1 ? string.Empty : ", "); } eKey.Columns = columns.ToString(); keys.Add(eKey); } #endregion #region Default constraints restrict3[0] = null; restrict3[1] = null; restrict3[2] = eTable.Name; dtShema = SqlSchemaFactory.GetSchema(con, "DefaultConstraints", restrict3); for (var x = 0; x < dtShema.Rows.Count; x++) { var cRow = dtShema.Rows[x]; var eKey = new KeySchema { KeyType = ConstraintType.Default, Name = cRow["CONSTRAINT_NAME"].ToString(), Columns = cRow["COLUMN_NAME"].ToString(), Source = UnBracket.ParseUnBracket(cRow["SOURCE"].ToString()) }; keys.Add(eKey); } #endregion return keys; }