Microsoft Exam Questions

Which query expression should you use?

You are developing a new feature in the application to display a list of all bundled products.
You need to write a LINQ query that will return a list of all bundled products. Which query expression should you use?

A.
context.Parts.Cast<Product>()
.Where(p => p.Descendants.Any(d => d is Product))

B.
context.Parts.OfType<Product>()
.Where(p => p.Descendants.Any(d => d is Product))

C.
context.Parts.Cast<Product>()
.ToList()
.Where(p => p.Descendants.Any(d => d is Product))

D.
context.Parts.OfType<Product>()
.ToList()
.Where(p => p.Descendants.Any(d => d is Product))

Explanation:
OfType() Filters the elements of an IEnumerable based on a specified type.

Enumerable.OfType<TResult> Method
(http://msdn.microsoft.com/en-us/library/bb360913.aspx)