exam questions

Exam 70-487 All Questions

View all questions & answers for the 70-487 exam

Exam 70-487 topic 1 question 68 discussion

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

You are developing an order processing application that uses the Entity Framework against a SQL Server database. Lazy loading has been disabled. The application displays orders and their associated order details. Order details are filtered based on the category of the product in each order.

You need to return orders with their filtered list of order details included in a single round trip to the database.
Which code segment should you use?
A.

B.

C.

D.


C -

Show Suggested Answer Hide Answer
Suggested Answer: Explanation
Eager loading is the process whereby a query for one type of entity also loads related entities as part of the query. Eager loading is achieved by use of the Include method. For example, the queries below will load blogs and all the posts related to each blog. using (var context = new BloggingContext())
{
// Load all blogs and related posts
var blogs1 = context.Blogs
.Include(b => b.Posts)
.ToList();
It is also possible to eagerly load multiple levels of related entities.
References:
https://msdn.microsoft.com/en-us/library/jj574232(v=vs.113).aspx

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
dosper
Highly Voted 5 years, 6 months ago
correct is B
upvoted 5 times
dosper
5 years, 6 months ago
It's A, the question mentions "return orders with their filtered list of order details" so with A when you do the .ToList() the engine will get all this info, with B it will only get the Orders without the details. So answer it's A
upvoted 20 times
tiger25
5 years, 4 months ago
Correct, answer is A. If B there will be multiple round trips when we try get OrderDetails info.
upvoted 4 times
...
Dreamchaser1980
4 years, 8 months ago
Answer A is correct. I verified it on my computer using EF Core, Answer A results in one query executed on the database. The result is a list of orders and its corresponding order details. Note the query is executed when you call ToList(), the final Select(r => r.Order) statement is done client side, which results in a IEnumerable<Order> list.
upvoted 7 times
...
...
...
UweJ
Most Recent 5 years, 1 month ago
I have tried all 4 answers in Visual Studio. None of these 4 produces the described result.
upvoted 3 times
UweJ
5 years, 1 month ago
This would in my opinion delviver what was asked for; var orders = db.Orders.Select(o => new { order = o, filteredOrderDetails = o.OrderDetails.Where(od => od.Product.Category.CategoryName == categoryName) }).ToList();
upvoted 2 times
...
...
rj001
5 years, 4 months ago
it's A
upvoted 4 times
...
MaverickCalibre
5 years, 5 months ago
Correct answer is A – as A materializes the orders to a list (to prevent round tripping)
upvoted 4 times
...
bobtables
5 years, 6 months ago
This is a bad question. Why isn't the answer D? Also, since they are using "Contains()", why don't they use ToHashSet() rather than ToList()?
upvoted 1 times
bobtables
5 years, 6 months ago
Plus the variables for C & D are wrong. The first variable should be named "var orderDetails = ..."
upvoted 2 times
...
tiger25
5 years, 4 months ago
C and D will have multiple round trips.
upvoted 4 times
...
Natali
5 years ago
in C and D you call db.Table, ToList the result, and then again call db.Table
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 ...