...

/

Creating a Repository Method to Get Questions

Creating a Repository Method to Get Questions

Learn about repository patterns to obtain a list of questions.

Implementation of repository method to get questions

Let’s implement the GetQuestions method first:

  1. Let’s add a couple of using statements at the top of the file for the Microsoft SQLc lient library, as well as Dapper:

Press + to interact
using Microsoft.Data.SqlClient;
using Dapper;
  1. In the GetQuestions method, overwrite the statement that throws a NotImplementedException by declaring a new database connection:

Press + to interact
public IEnumerable<QuestionGetManyResponse>
GetQuestions()
{
using (var connection = new
SqlConnection(_connectionString))
{
}
}

Notice that we’ve used a using block to declare the database connection.

Note: A using block automatically disposes of the ...