Writing Data Using Dapper
Learn to implement data manipulation methods with Dapper.
In this section, we are going to implement methods in our data repository that will write to the database. We will start by extending the interface for the repository and then do the actual implementation.
The stored procedures that perform the write operations are already in the database. We will be interacting with these stored procedures using Dapper.
Adding methods to write data to the repository interface
We’ll start by adding the necessary methods to the repository interface:
Press + to interact
public interface IDataRepository{...QuestionGetSingleResponsePostQuestion(QuestionPostRequest question);QuestionGetSingleResponsePutQuestion(int questionId, QuestionPutRequestquestion);void DeleteQuestion(int questionId);AnswerGetResponse PostAnswer(AnswerPostRequest answer);}
Here, we must implement some methods that will add, change, and delete questions, as well as adding an answer.