Questions

Try to answer the following questions to check the knowledge that you have gained in this chapter:

  1. We have the following code in a data repository that uses Dapper's multi result feature to return a single order with the many related detail lines in a single database call: 
using (var connection = new SqlConnection(_connectionString))
{
connection.Open();

using (GridReader results = connection.QueryMultiple(
@"EXEC dbo.Order_GetHeader @OrderId = @OrderId;
EXEC dbo.OrderDetails_Get_ByOrderId @OrderId = @OrderId",
new { OrderId = orderId }))
{

// TODO - Read the order and details from the query result

return order;
}
}

What are the missing statements that will read the order and its details from the results putting the details in the order model? The order model is of the OrderGetSingleResponse type and contains a Details property of the IEnumerable<OrderDetailGetResponse> type.

  1. What is the downside of using Dapper's multi-mapping feature when reading data from a many to one-related table in a single database call?
  2. How does data paging help performance?
  3. Does making code asynchronous make it faster?
  1. What is the problem with the following asynchronous method?
public async AnswerGetResponse GetAnswer(int answerId)
{
using (var connection = new SqlConnection(_connectionString))
{
connection.Open();
return await connection
.QueryFirstOrDefaultAsync<AnswerGetResponse>(
"EXEC dbo.Answer_Get_ByAnswerId @AnswerId = @AnswerId",
new { AnswerId = answerId });
}
}
  1. Why it is a good idea to have a size limit on a memory cache?
  2. In our QuestionCache implementation, when adding a question to the cache, how can we invalidate that item in the cache after 30 minutes?
  3. When we registered our QuestionCache class for dependency injection, why did we use the AddSingleton method and not the AddScoped method like in the following code?
services.AddScoped<QuestionCache>();
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.25.161