exam questions

Exam 70-487 All Questions

View all questions & answers for the 70-487 exam

Exam 70-487 topic 1 question 17 discussion

Actual exam question from Microsoft's 70-487
Question #: 17
Topic #: 1
[All 70-487 Questions]

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 all orders along with customer information. Lazy loading has been disabled.
The Order class is shown below.

You need to return the orders and customer information in a single round trip to the database.
Which code segment should you use?

  • A. Option A
  • B. Option B
  • C. Option C
  • D. Option D
Show Suggested Answer Hide Answer
Suggested Answer: A 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
supersunny
Highly Voted 5 years, 4 months ago
This is the case of lazy loading so A is suitable.
upvoted 10 times
...
Dreamchaser1980
Highly Voted 4 years, 9 months ago
The answer is A. Using the include statement is called eager loading. The IQueryable<Order> query is executed on the database when it is returned to the View in the orders.ToList() statement, this is called deferred execution. So there is only one roundtrip to the database. I double checked the code on my computer.
upvoted 8 times
...
Ptu12125
Most Recent 4 years, 5 months ago
Lazy loading is disabled. Correct answer is C. "Loading of related entities can still be achieved using eager loading (see Eagerly Loading above) or the Load method (see Explicitly Loading below)." Ref: https://docs.microsoft.com/en-us/ef/ef6/querying/related-data
upvoted 1 times
Ptu12125
4 years, 5 months ago
Sorry, A is correct due to deferred execution, it will call the query only once.
upvoted 1 times
...
...
Tinashe16
4 years, 6 months ago
A is correct. For eager loading, use Include keyword, and it should be immediately after your DbSet.
upvoted 2 times
...
mmk1991
5 years, 3 months ago
Correct answer is C, since it says lazy loading has been disabled. See ExplicitLoading in https://docs.microsoft.com/en-us/ef/ef6/querying/related-data
upvoted 5 times
Karel_Gott
5 years, 3 months ago
Lazy loading has been DISABLED means, that entities will be loaded automatically when you ACCESS them. So the correct answer is A.
upvoted 3 times
nsch
5 years, 3 months ago
Even with lazy loading disabled it is still possible to lazily load related entities, but it must be done with an explicit call. To do so you use the Load method on the related entity’s entry. https://docs.microsoft.com/en-us/ef/ef6/querying/related-data
upvoted 1 times
SirMarv
5 years, 2 months ago
Very correct that we can still lazily load related entities, but that analogy would apply if we were trying to lazily load entities even with Lazy Loading disabled, so A is the correct answer.
upvoted 3 times
tanujgyan
5 years ago
In my opinion A is correct. Its Eager loading. Also whenever they talk about explicit loading they mention Reference or Collection methods and not select method and I might be wrong here but I dont think C will work
upvoted 5 times
...
...
...
...
mchen
5 years, 2 months ago
C is correct
upvoted 2 times
mr_
4 years, 11 months ago
In my opinion C is wrong. Correct answer is A. '(...) in a single round trip to the database' C is wrong because it will perform two round trips to the DB - first on Load(), second on ToList(). Answer A is correct because there will be single round trip (single SELECT-LEFT-JOIN statemet). Tested with SQL Server Profiler.
upvoted 8 times
...
...
...
mmk1991
5 years, 3 months ago
Relevant docs: https://docs.microsoft.com/en-us/ef/ef6/querying/related-data
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...