Search⌘ K
AI Features

Writing Data Using Dapper

Explore how to implement data writing operations with Dapper in ASP.NET Core. Understand extending repository interfaces, executing stored procedures to add, update, and delete questions, and inserting answers. Gain practical experience creating model classes and repository methods for effective database interaction.

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:

Node.js
public interface IDataRepository
{
...
QuestionGetSingleResponse
PostQuestion(QuestionPostRequest question);
QuestionGetSingleResponse
PutQuestion(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.

Creating a repository method to add a

...