Now using the SelectMany operator, collect all the distinct Ingredients
required for all items.
Chapter 7
[ 179 ]
List
itemss = GetNewItemsList();
IEnumerable ingredients = itemss.
SelectMany(ing => ing.Ingredients);
Console.WriteLine("List of all Ingredients for the Icecreams");
foreach (string str in ingredients.Distinct())
{
Console.WriteLine(str);
}
The output of this code would be a collection of ingredients for each item.
Join Operators
A join is an association of objects from different data sources that share a common
attribute. These operators perform the same operations that are performed by the
database queries. Each data source will have certain key attributes by which we can
compare the values, and collect information. The different join operators are covered
in detail in the following sub-sections.
Join
This operator joins two sequences, based on matching keys extracted from elements
in sequences.
public static IEnumerable Join
(
IEnumerable outer,
IEnumerable inner,
Func outerKeySelector,
Func innerKeySelector,
Func resultSelector
)
public static IQueryable Join
(
IQueryable outer,
IEnumerable inner,
Expression> outerKeySelector,
Expression> innerKeySelector,
Expression> resultSelector
)
Standard Query Operators
[ 180 ]
The IEqualityComparer is used to compare keys.
Pages:
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272