Which LINQ to Entities query should you use?

You are developing an ASP.NET web application.
The application includes the following Entity Data Model (EDM):

You instantiate an ObjectContextfor the EDM named context.
You need to find the total number of addresses thatare associated with customers that have a non-nullmiddle
name.
Which LINQ to Entities query should you use?

You are developing an ASP.NET web application.
The application includes the following Entity Data Model (EDM):

You instantiate an ObjectContextfor the EDM named context.
You need to find the total number of addresses thatare associated with customers that have a non-nullmiddle
name.
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();



Leave a Reply 0

Your email address will not be published. Required fields are marked *