public TableRelation Add(string parentTable, IList<string> parentColumns, string childTable, IList<string> childColumns) { if (parentTable == null) throw ExceptionBuilder.ArgumentNull("parentTable"); if (parentColumns == null) throw ExceptionBuilder.ArgumentNull("parentColumns"); if (parentColumns.Count == 0) throw ExceptionBuilder.ArgumentArrayMustNotBeEmpty("parentColumns"); if (childTable == null) throw ExceptionBuilder.ArgumentNull("childTable"); if (childColumns == null) throw ExceptionBuilder.ArgumentNull("childColumns"); if (childColumns.Count == 0) throw ExceptionBuilder.ArgumentArrayMustNotBeEmpty("childColumns"); TableBinding parentTableBinding = _dataContext.Tables[parentTable]; TableBinding childTableBinding = _dataContext.Tables[childTable]; if (parentTableBinding == null) throw ExceptionBuilder.ParentTableMustExistInDataContext("parentTable"); if (childTableBinding == null) throw ExceptionBuilder.ChildTableMustExistInDataContext("childTable"); return Add(parentTableBinding, parentColumns, childTableBinding, childColumns); }
public TableRelation(IList <ColumnBinding> parentColumns, IList <ColumnBinding> childColumns) { if (parentColumns == null) { throw ExceptionBuilder.ArgumentNull("parentColumns"); } if (childColumns == null) { throw ExceptionBuilder.ArgumentNull("childColumns"); } if (parentColumns.Count == 0) { throw ExceptionBuilder.ArgumentArrayMustNotBeEmpty("parentColumns"); } if (childColumns.Count != parentColumns.Count) { throw ExceptionBuilder.ArgumentArrayMustHaveSameSize("childColumns", "parentColumns"); } TableBinding parentTable = parentColumns[0].Table; TableBinding childTable = childColumns[0].Table; for (int i = 1; i < parentColumns.Count; i++) { if (parentColumns[i].Table != parentTable) { throw ExceptionBuilder.AllColumnsMustBelongToSameTable("parentColumns"); } } for (int i = 1; i < childColumns.Count; i++) { if (childColumns[i].Table != childTable) { throw ExceptionBuilder.AllColumnsMustBelongToSameTable("childColumns"); } } _parentColumns = new ColumnBindingCollection(parentColumns); _childColumns = new ColumnBindingCollection(childColumns); }
public TableRelation Add(TableBinding parentTable, IList<string> parentColumns, TableBinding childTable, IList<string> childColumns) { if (parentTable == null) throw ExceptionBuilder.ArgumentNull("parentTable"); if (parentColumns == null) throw ExceptionBuilder.ArgumentNull("parentColumns"); if (parentColumns.Count == 0) throw ExceptionBuilder.ArgumentArrayMustNotBeEmpty("parentColumns"); if (childTable == null) throw ExceptionBuilder.ArgumentNull("childTable"); if (childColumns == null) throw ExceptionBuilder.ArgumentNull("childColumns"); if (childColumns.Count == 0) throw ExceptionBuilder.ArgumentArrayMustNotBeEmpty("childColumns"); ColumnBinding[] parentColumnBindings = new ColumnBinding[parentColumns.Count]; for (int i = 0; i < parentColumnBindings.Length; i++) { parentColumnBindings[i] = parentTable.GetColumn(parentColumns[i]); if (parentColumnBindings[i] == null) throw ExceptionBuilder.ParentColumnNotFound("parentColumns", parentTable, parentColumns[i]); } ColumnBinding[] childColumnBindings = new ColumnBinding[childColumns.Count]; for (int i = 0; i < childColumnBindings.Length; i++) { childColumnBindings[i] = childTable.GetColumn(childColumns[i]); if (childColumnBindings[i] == null) throw ExceptionBuilder.ChildColumnNotFound("childColumns", childTable, childColumns[i]); } return Add(parentColumnBindings, childColumnBindings); }