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); }
private void BeforeInsert(TableRelation tableRelation) { // Ensure that parent and child table are within the data context. if (_dataContext.Tables[tableRelation.ParentTable.Name] == null) throw ExceptionBuilder.ParentTableMustExistInDataContext("tableRelation"); if (_dataContext.Tables[tableRelation.ChildTable.Name] == null) throw ExceptionBuilder.ChildTableMustExistInDataContext("tableRelation"); // Ensure that no table relation with the same parent and child columns exists. foreach (TableRelation existingTableRelation in this) { if (existingTableRelation.ParentTable == tableRelation.ParentTable && existingTableRelation.ChildTable == tableRelation.ChildTable) { // TODO: Compare the two and make sure that permutations of parent columns and // child columns do not make any difference. } } }