You are developing an ASP.NET Web application. The application includes the following Entity Data
Mmodel (EDM)
You instantiate an ObjectContext for the EDM named context You need to find the total number of
addresses that are assosiated with customers that have a nonull mode. Which LINQ to Entities query
should you use?
A.
var query = context.Customers
.Where(c => c.MiddleName != null)
.Select(c => c.CustomerAddresses.Count();
B.
var query = context.Customers
.Where(c => c.MiddleName != null)
.SelectMany(c => c.CustomerAddresses.Count();
C.
var query = context.Addresses
.SelectMany(a => a.CustomerAddresses.OfType<Customer>()
.Where(c => c.MiddleName != null)).Count();
D.
var query = context.Addresses
.GroupBy(a => a.CustomerAddresses
.Where(ca => ca.Customer.MiddleName != null)).Count();
These 2 say the answer is B.
http://www.aiotestking.com/microsoft/which-linq-to-entities-query-should-you-use/
http://www.aiotestking.com/microsoft/which-linq-to-entities-query-should-you-use-3/