How to get up and running with Dapper ORM on Asp .NET

Example: Create a basic CRUD web app to manage events.

First things first

  1. Create a new Empty ASP .NET Core Web Project
  2. Create a new database with a table called <anything-really>
  3. Install dapper using NuGet PM or use any other method you like

A. Define your data model(s)

  • In the root of the project, create a file inside ./Models/Event.cs
  • Define your model as follows:
  • Note that you can add any properties you like, provided that they match with the column names in your table(s)

B. Create a service or class to access your data

  • In this case, we will create a service called EventService.cs inside a folder called Services
  • Example of a connection string:

C. Check if everything works as expected :)

  • So far we have only implemented the R in our desired CRUD functionality, but it shouldn't be too hard to implement the remaining portions i.e. CUD
  • You can refer to the official Dapper documentation if you get stuck.

Written by

Former Glorified Electrician(aka Electrical Engineer). Now a Software Developer working on complex Enterprise Software. Lets connect on twitter @NdamuleloNemakh

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store