/// <summary> /// Gets the collection of entries where the given table name is used. /// </summary> /// <param name="table">The table name of the member to find, or null to refer to the /// default one in this context.</param> /// <returns>The requested collection of entries.</returns> public IEnumerable <ISchemaEntry> FindTable(string table) { if (IsDisposed) { throw new ObjectDisposedException(this.ToString()); } table = Core.SchemaEntry.ValidateTable(table); var alias = (IElementAlias)(table == null ? null : Aliases.FindAlias(table)); if (alias != null) { table = alias.Element; } return(_Members.FindTable(table)); }
/// <summary> /// Returns the member whose table and column name are given, or null if not such member /// can be found. /// </summary> /// <param name="table">The table name of the member to find, or null to refer to the /// default one in this context.</param> /// <param name="column">The column name.</param> /// <returns>The member found, or null.</returns> public ISchemaEntry FindEntry(string table, string column) { if (IsDisposed) { throw new ObjectDisposedException(this.ToString()); } table = Core.SchemaEntry.ValidateTable(table); column = Core.SchemaEntry.ValidateColumn(column); var alias = (IElementAlias)(table == null ? null : Aliases.FindAlias(table)); if (alias != null) { table = alias.Element; } return(_Members.FindEntry(table, column)); }
/// <summary> /// Adds the given orphan instance into this collection. /// </summary> /// <param name="member">The orphan instance to add into this collection.</param> public void Add(ISchemaEntry member) { if (IsDisposed) { throw new ObjectDisposedException(this.ToString()); } if (member == null) { throw new ArgumentNullException("member", "Member cannot be null."); } if (member.IsDisposed) { throw new ObjectDisposedException(member.ToString()); } if (object.ReferenceEquals(this, member.Owner)) { return; } if (member.Owner != null) { throw new NotOrphanException( "Cannot add member '{0}' into this '{1}' because it is not orphan." .FormatWith(member, this)); } Core.SchemaEntry.ValidateTable(member.TableName); Core.SchemaEntry.ValidateColumn(member.ColumnName); var alias = (IElementAlias)(member.TableName == null ? null : Aliases.FindAlias(member.TableName)); if (alias != null) { member.TableName = alias.Element; } var temp = FindEntry(member.TableName, member.ColumnName); if (temp != null) { throw new DuplicateException( "Cannot add member '{0}' into this '{1}' because its name is already used." .FormatWith(member, this)); } var list = FindColumn(member.ColumnName).ToList(); if (list.Count != 0) { if (member.TableName == null) { throw new DuplicateException( "Cannot add member '{0}' into this '{1}' because its column is already used in a non-default table." .FormatWith(member, this)); } temp = list.Find(x => x.TableName == null); if (temp != null) { throw new DuplicateException( "Cannot add member '{0}' into this '{1}' because its name is already used in the default table." .FormatWith(member, this)); } } _Members.Add(member); // To intercept re-entrant operation... member.Owner = this; }