Which code segment should you use?

You are developing an ASP.NET MVC application. The application is an order processing system that uses the
ADO.NET Entity Framework against a SQL Server database. It has a controller that loads a page that displays
customers. Customers are filtered on Country and, if provided, on CompanyName.
You have an Entity Framework context named db.
The Customer class is shown below.

You need to execute a single deferred query to return the filtered list of customers.
Which code segment should you use?

You are developing an ASP.NET MVC application. The application is an order processing system that uses the
ADO.NET Entity Framework against a SQL Server database. It has a controller that loads a page that displays
customers. Customers are filtered on Country and, if provided, on CompanyName.
You have an Entity Framework context named db.
The Customer class is shown below.

You need to execute a single deferred query to return the filtered list of customers.
Which code segment should you use?

A.
Option A

B.
Option B

C.
Option C

D.
Option D



Leave a Reply 4

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


johnykiza

johnykiza

I think A is correct.
Why use ‘query.Load’ ?

Jorge

Jorge

johnykiza, I agree with you. “A” is the best option.

Jeroen Brattinga

Jeroen Brattinga

I don’t see a need for query.Load() either. The ToLower().StartsWith() in the company .Where() filter can be perfectly handled by EF and will be passed to the database (e.g. to a SQL statement: LIKE ‘companyname%’).

The unnecessary query.Load() will result in transferring more data from the database that will be filtered in the lines following it.

A should be the correct answer.

puvpul

puvpul

In the question it says deffered query and that might be the reason.