/// <summary> /// Creates a relation to a child table /// </summary> /// <typeparam name="T">The child type</typeparam> /// <param name="name">The name of the relation</param> /// <param name="parentColumnName">The parent column name, i.e. name of column in this table</param> /// <param name="childColumnName">The child column name, i.e. name of column in child table T</param> /// <param name="acceptRejectRule">The accept/reject rule to apply to child rows</param> /// <param name="deleteRule">The delete rule to apply to child rows</param> /// <param name="childColumnDefaultValue">Default value for child column. Needed when <paramref name="deleteRule"/> is Rule.SetDefault</param> protected void CreateParentChildRelation <T> ( string name, string parentColumnName, string childColumnName, AcceptRejectRule acceptRejectRule = AcceptRejectRule.None, Rule deleteRule = Rule.Cascade, object childColumnDefaultValue = null ) where T : TableBase { if (string.IsNullOrEmpty(name)) { throw new ArgumentNullException(nameof(name)); } if (string.IsNullOrEmpty(parentColumnName)) { throw new ArgumentNullException(nameof(parentColumnName)); } if (string.IsNullOrEmpty(childColumnName)) { throw new ArgumentNullException(nameof(childColumnName)); } var child = Controller.GetTable <T>(); DataRelation r = new DataRelation(name, Columns[parentColumnName], child.Columns[childColumnName]); ChildRelations.Add(r); r.ChildKeyConstraint.AcceptRejectRule = acceptRejectRule; r.ChildKeyConstraint.DeleteRule = deleteRule; child.Columns[childColumnName].DefaultValue = childColumnDefaultValue; }
/// <summary> /// Add child information. /// </summary> /// <param name="childTaxonTreeNode">Child taxon tree node.</param> /// <param name="childTaxonRelation">Child taxon relation.</param> public void AddChild(TaxonTreeNode childTaxonTreeNode, WebTaxonRelation childTaxonRelation) { Int32 childIndex; if (Children.IsEmpty() || Children[Children.Count - 1].SortOrder <= childTaxonTreeNode.SortOrder) { // Insert at the end of the lists. if (Children.IsNull()) { ChildRelations = new List <WebTaxonRelation>(); Children = new List <TaxonTreeNode>(); } ChildRelations.Add(childTaxonRelation); Children.Add(childTaxonTreeNode); } else { // Insert into the list. for (childIndex = 0; childIndex < Children.Count; childIndex++) { if (childTaxonTreeNode.SortOrder < Children[childIndex].SortOrder) { ChildRelations.Insert(childIndex, childTaxonRelation); Children.Insert(childIndex, childTaxonTreeNode); break; } } } }
public JackpotLedgerTable(DataSet dataSet) { InitColumns(); dataSet.Tables.Add(this); DataTable child = dataSet.Tables["jackpot_ledger_rows"]; if (child != null) { ChildRelations.Add(new DataRelation("jackpot_rows", base.PrimaryKey[0], child.Columns[JackpotLedgerTable.PrimaryKey])); ChildRelations.Add(new DataRelation("jackpot_from_rows", base.PrimaryKey[0], child.Columns["jackpot_ledger_from_id"])); } //Columns.Add( PrizeExceptionSet.PrimaryKey, XDataTable.DefaultAutoKeyType ); //Columns.Add( PriceExceptionSet.PrimaryKey, XDataTable.DefaultAutoKeyType ); //Columns.Add( SessionTypeTable.PrimaryKey, XDataTable.DefaultAutoKeyType ); }