DataSet dataSet = new DataSet();
DataTable dataTableGender = new DataTable();
DataTable dataTableHuman = new DataTable();
DataTable dataTableDog = new DataTable();
dataTableGender.TableName=nameof(dataTableGender);
dataTableHuman.TableName=nameof(dataTableHuman);
dataTableDog.TableName=nameof(dataTableDog);
dataSet.Tables.Add(dataTableGender);
dataSet.Tables.Add(dataTableHuman);
dataSet.Tables.Add(dataTableDog);
dataTableGender.Columns.Add("Gender");
dataTableGender.Rows.Add("male");
dataTableGender.Rows.Add("female");
dataTableGender.Rows.Add("other");
dataTableHuman.Columns.Add("Name");
dataTableHuman.Columns.Add("Gender");
dataTableHuman.Columns.Add("Age");
dataTableHuman.Rows.Add("HumanName1", "male", 1);
dataTableHuman.Rows.Add("HumanName2", "female", 2);
dataTableHuman.Rows.Add("HumanName3", "other", 3);
dataTableHuman.Rows.Add("HumanName4", "male", 4);
dataTableHuman.Rows.Add("HumanName5", "female", 5);
dataTableHuman.Rows.Add("HumanName6", "other", 6);
dataTableDog.Columns.Add("Name");
dataTableDog.Columns.Add("Gender");
dataTableDog.Columns.Add("Age");
dataTableDog.Rows.Add("DogName1", "male", 1);
dataTableDog.Rows.Add("DogName2", "female", 2);
dataTableDog.Rows.Add("DogName3", "male",3);
dataTableDog.Rows.Add("DogName4", "female", 4);
dataSet.Relations.Add("HumanRelation", dataTableGender.Columns["Gender"], dataTableHuman.Columns["Gender"]);
dataSet.Relations.Add("DogRelation", dataTableGender.Columns["Gender"], dataTableDog.Columns["Gender"]);
foreach (DataRow row in dataSet.Tables[nameof(dataTableGender)].Rows)
{
Console.WriteLine("Gender: " + row["Gender"]);
foreach (DataRow childRow in row.GetChildRows("HumanRelation"))
{
Console.WriteLine("Human: " + childRow["Name"]);
}
foreach (DataRow childRow in row.GetChildRows("DogRelation"))
{
Console.WriteLine("Dog: " + childRow["Name"]);
}
Console.WriteLine();
}
Console.Read();