...
/Creating a Repository Method to Get Questions
Creating a Repository Method to Get Questions
Learn about repository patterns to obtain a list of questions.
We'll cover the following...
Implementation of repository method to get questions
Let’s implement the GetQuestions method first:
Let’s add a couple of
usingstatements at the top of the file for the Microsoft SQLc lient library, as well asDapper:
Press + to interact
using Microsoft.Data.SqlClient;using Dapper;
In the
GetQuestionsmethod, overwrite the statement that throws aNotImplementedExceptionby declaring a new database connection:
Press + to interact
public IEnumerable<QuestionGetManyResponse>GetQuestions(){using (var connection = newSqlConnection(_connectionString)){}}
Notice that we’ve used a using block to declare the database connection.
Note: A
usingblock automatically disposes of the ...
Ask