It looks complex but it's simple really. I'll try to explain in comments:
private static void Main()
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new []
{
new DataColumn("PassA",typeof(string)),
new DataColumn("PassB",typeof(string)),
new DataColumn("Other",typeof(string)),
});
DataRow row = dt.NewRow();
row["PassA"] = "1,2,3";
row["PassB"] = "1,2";
row["Other"] = "X";
dt.Rows.Add(row);
row = dt.NewRow();
row["PassA"] = "1,3";
row["PassB"] = "2";
row["Other"] = "Y";
dt.Rows.Add(row);
var fullList =
dt.Rows.Cast<DataRow>().Select(i => new
{
PassA = i["PassA"].ToString().Split(','),
PassB = i["PassB"].ToString().Split(','),
Other = i["Other"].ToString()
})
.SelectMany(i =>
i.PassA.SelectMany(
a => i.PassB,
(a, b) => new {a, b, i.Other}));
fullList.ToList().ForEach(i =>
{
Console.WriteLine("{0}\t{1}\t{2}",i.a,i.b,i.Other);
});
}
I hope that makes sense. if not then let me know ^_^
Andy
UPDATE: Changes test data from POCO to DataTable:
The main logic is intact. I still convert the initial object (now datatable) to anon as before