title: Purpose of ForeignKeyConstraint.AcceptRejectRule in ADO.Net?
body: <p>What is the purpose in life of the <a href="http://msdn.microsoft.com/en-us/library/system.data.foreignkeyconstraint.acceptrejectrule.aspx" rel="nofollow">AcceptRejectRule</a> property of ForeignKeyConstraint class in ADO.Net?</p>
  
  <p>The MSDN Document doesn't carry sufficient explanation (for me) to make its purpose clear. After reading the documentation, I thought that setting the property to None will prevent cascading of any changes from the parent table to the child table. But, this assumption was proved to be wrong after running the following code:</p>
  
  <pre><code>       DataTable table1 = new DataTable("Customers");
  
          table1.Columns.Add(new DataColumn("CustomerID", typeof(int)));
          table1.Columns.Add(new DataColumn("CustomerName", typeof(string)));
  
          DataTable table2 = new DataTable("Orders");
          table2.Columns.Add(new DataColumn("OrderID", typeof(int)));
          table2.Columns.Add(new DataColumn("CustomerID", typeof(int)));
  
          DataSet dataSet = new DataSet();
          dataSet.Tables.AddRange(new DataTable[] { table1, table2 });
          dataSet.EnforceConstraints = true;
  
          DataRelation dataRelation = new DataRelation("CustomerOrders", table1.Columns["CustomerID"],
              table2.Columns["CustomerID"], true);
          dataSet.Relations.Add(dataRelation);
  
          Debug.WriteLine("No. of constaints in the child table = {0}", table2.Constraints.Count);
  
          dataRelation.ChildKeyConstraint.AcceptRejectRule = AcceptRejectRule.None;
          dataRelation.ChildKeyConstraint.DeleteRule = Rule.Cascade;
          dataRelation.ChildKeyConstraint.UpdateRule = Rule.Cascade;
  
          table1.Rows.Add(new object[] { 11, "ABC" });
          table1.Rows.Add(new object[] { 12, "XYZ" });
  
          table2.Rows.Add(new object[] { 51, 12 });
          table2.Rows.Add(new object[] { 52, 11 });
          table2.Rows.Add(new object[] { 53, 11 });
  
          table1.Rows.RemoveAt(0);
          table1.AcceptChanges();
          table2.AcceptChanges();
  
          Debug.WriteLine("No of rows in the parent table = {0}", table1.Rows.Count);
          Debug.WriteLine("No of rows in the child table = {0}", table2.Rows.Count);
  </code></pre>
  
  <p>The output of the above code is: <br /></p>
  
  <p><strong>No. of constaints in the child table = 1 <br />
  No of rows in the parent table = 1 <br />
  No of rows in the child table = 1</strong> <br /></p>
  
  <p>Thanks, <br />
  Dinesh</p>