[Mono-bugs] [Bug 79689][Min] New - Parent and child columns can't be the same column - Exception

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Tue Oct 17 20:16:24 EDT 2006

Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by anagappan at novell.com.


--- shadow/79689	2006-10-17 20:16:24.000000000 -0400
+++ shadow/79689.tmp.25910	2006-10-17 20:16:24.000000000 -0400
@@ -0,0 +1,105 @@
+Bug#: 79689
+Product: Mono: Class Libraries
+Version: 1.1
+OS Details: 
+Status: NEW   
+Priority: Minor
+Component: Sys.Data
+AssignedTo: anagappan at novell.com                            
+ReportedBy: anagappan at novell.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+Summary: Parent and child columns can't be the same column - Exception
+Please fill in this template when reporting a bug, unless you know what you
+are doing.
+Description of Problem:
+I ran across this problem while trying to make an older .NET application of
+mine Mono-compliant. In a nutshell, I have this DataTable:
+(+) signifies a primary key column. 
+I also have a foreign key (composite) pointing to the same table : (ID,
+Culture) <- (ParentID, Culture). Mono throws an exception when adding the
+foreign key to the DataTable:
+Unhandled Exception: System.InvalidOperationException: Parent and child
+can't be the same column.
+This would have been correct if I had tried to add a simple FK like (Culture
+<- Culture), but IMO for a composite key there should be no error. The code
+should check whether _all_ columns involved are identical, and then throw
+the exception.
+Now, I know this is a pretty ugly way to model such a situation, but the
+point is MS .NET allows this (and at least SQL Server accepts such a data
+Below is a small app to illustrate this problem. It can be made into a unit
+test rather easily, and I will do it if this belongs in Bugzilla.
+Steps to reproduce the problem:
+1. http://lists.ximian.com/pipermail/mono-devel-list/2006-October/020911.html
+Actual Results:
+Exception thrown
+Expected Results:
+No exception
+How often does this happen? 
+Additional Information:
+using System.Data;
+namespace TestSelfReference
+	class Class1
+	{
+		static void Main(string[] args)
+		{
+			// create a table and some columns
+			DataTable dataTable = new DataTable("Menu");
+			DataColumn colID = dataTable.Columns.Add("ID",
+			DataColumn colCulture =
+dataTable.Columns.Add("Culture", typeof(string));
+			DataColumn colName = dataTable.Columns.Add("Name",
+			DataColumn colParentID =
+dataTable.Columns.Add("ParentID", typeof(int));
+			// table PK (ID, Culture)
+			dataTable.Constraints.Add(new UniqueConstraint(
+				"MenuPK", 
+				new DataColumn[] {colID, colCulture}, 
+				true));
+			// add a FK referencing the same table: (ID,
+Culture) <- (ParentID, Culture)
+			ForeignKeyConstraint fkc = new ForeignKeyConstraint(
+				"MenuParentFK", 
+				new DataColumn[] {colID, colCulture}, 
+				new DataColumn[] {colParentID, colCulture});
+			dataTable.Constraints.Add(fkc); // !! Mono throws
+		}
+	}

More information about the mono-bugs mailing list