You create an application for an online store by using the Microsoft .NET Framework 3.5
and Microsoft ADO.NET.You write the following code segment. (Line numbers are
included for reference only.)
01 DataTable dtProducts = new DataTable();
02 dtProducts.Columns.Add(“ProductID”);
03 dtProducts.Columns.Add(“ProductName”);
04 dtProducts.Columns.Add(“CategoryID”);
05 dtProducts.Rows.Add(1, “Milk”, 1);
06 dtProducts.Rows.Add(2, “Beef”, 2);
07 dtProducts.Rows.Add(3, “Butter”, 1);
08 dtProducts.Rows.Add(4, “Sausage”, 2);
09 DataTable dtCategories = new DataTable();
10 dtCategories.Columns.Add(“CategoryID”);
11 dtCategories.Columns.Add(“CategoryName”);
12 dtCategories.Rows.Add(1, “Dairy products”);
13 dtCategories.Rows.Add(2, “Meat”);
14 var products = dtProducts.AsEnumerable();
15 var categories = dtCategories.AsEnumerable();
16
17 foreach (var element in result) {
18 Console.WriteLine(element);
19 }
When the dtProducts DataTable has the same value in the CategoryID column as the
dtCategories DataTable, the DataTables are related.You need to display for each product,
the product information and the product category. Which code segment should you insert at line 16?
A.
var result = products.Join( categories, p => p[“CategoryID”], c => c[“CategoryID”], (p, c)
=> new {
Name = p[“ProductName”], Category = c[“CategoryName”]
});
B.
var result = products.Join( categories, c => c[“CategoryID”], p => p[“CategoryID”], (c, p)
=> new { Name = p[“ProductName”], Category = c[“CategoryName”]
});
C.
var result = products.GroupJoin(
categories, p => p[“CategoryID”], c => c[“CategoryID”], (group, r) => new {
Name = group[“ProductName”], Category = group[“CategoryName”]
});
D.
var result = categories.GroupJoin(
products, p => p[“CategoryID”], c => c[“CategoryID”], (group, r) => new {
Name = group[“ProductName”], Category = group[“CategoryName”]
});