public DmRelation AddForeignKey(string relationName, DmColumn childColumn, DmColumn parentColumn) { // check if child column is from the current table if (!this.Columns.Contains(childColumn)) { throw new Exception("Child column should belong to the dmTable"); } DmRelation dr = new DmRelation(relationName, parentColumn, childColumn); this.DmSet.Relations.Add(dr); return(dr); }
public DmRelation AddForeignKey(DmRelation relation) { // check if child column is from the current table foreach (var c in relation.ChildColumns) { if (!this.Columns.Contains(c)) { throw new Exception("Child column should belong to the dmTable"); } } this.DmSet.Relations.Add(relation); return(relation); }
internal DmRelation Clone(DmSet destination) { DmTable parent = destination.Tables[ParentTable.TableName]; DmTable child = destination.Tables[ChildTable.TableName]; int keyLength = parentKey.Columns.Length; DmColumn[] parentColumns = new DmColumn[keyLength]; DmColumn[] childColumns = new DmColumn[keyLength]; for (int i = 0; i < keyLength; i++) { parentColumns[i] = parent.Columns[ParentKey.Columns[i].ColumnName]; childColumns[i] = child.Columns[ChildKey.Columns[i].ColumnName]; } DmRelation clone = new DmRelation(RelationName, parentColumns, childColumns); return(clone); }
/// <summary> /// Gets the parent row of this <see cref='System.Data.DataRow'/> /// using the specified <see cref='System.Data.DataRelation'/> and <see cref='System.Data.DataRowVersion'/>. /// </summary> public DmRow GetParentRow(DmRelation relation, DmRowVersion version) { if (relation == null) { return(null); } if (relation.DmSet != table.DmSet) { throw new Exception("RowNotInTheDataSet"); } if (relation.ChildKey.Table != table) { throw new Exception("RelationForeignTable"); } return(DmRelation.GetParentRow(relation.ParentKey, relation.ChildKey, this, version)); }
public virtual DmSet Clone() { DmSet ds = new DmSet(); ds.DmSetName = this.DmSetName; ds.CaseSensitive = this.CaseSensitive; ds.Culture = this.Culture; for (int i = 0; i < Tables.Count; i++) { DmTable dt = Tables[i].Clone(); ds.Tables.Add(dt); } List <DmRelation> rels = Relations; for (int i = 0; i < rels.Count; i++) { DmRelation rel = rels[i].Clone(ds); ds.Relations.Add(rel); } return(ds); }
/// <summary> /// Gets the parent rows of this DmRow using the specified DmRelation . /// </summary> public DmRow[] GetParentRows(DmRelation relation) => GetParentRows(relation, DmRowVersion.Default);
/// <summary> /// Gets the child rows of this DmRow using the /// specified DmRelation. /// </summary> public DmRow[] GetChildRows(DmRelation relation) => GetChildRows(relation, DmRowVersion.Default);