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 10

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


FigArt

FigArt

I don’t think that C is the correct answer because of the call to .Load(), this causes the query to execute immediately which is not what the question is asking for.

My preferred answer would be A

Blue

Blue

The Load extension method works just like ToList, except that it avoids the creation of the list altogether. So after calling Load, the data is filtered without any other trip to DB..
I think C is correct.

student

student

Why even call Load? I think correct answer is A.

Blah

Blah

If you used A, in the case where you don’t provide a value for CompanyName, the method will return null. customers isn’t assigned a value unless CompanyName has a value.

Mike

Mike

A is correct answer. (If ComapanyName is provided)

BlahBlah

BlahBlah

Customers collection will always be null if the CompanyName is not provided. I think this question is wrong…

nex-54

nex-54

Yes, you are right.
From this cases i prefer “A” as closest one, not “C”

Programmer

Programmer

Beside A and B is the same…

HRVAT

HRVAT

No it is not the same, A: IEnumerable twice and in B: once.

HRVAT

HRVAT

In the exam, i will go for A !