RESTFUL WEB API USING ASP.NET CORE 2.0 WITH MSSQL(using Dapper)

  1. Visual Studio 2017
  2. MSSQL server
  3. POSTMAN

STEPS TO CREATE A WEB API WITH CRUD OPERATIONS

  1. First create a database and a table using mssql.
Figure 1. Table creation
Figure 2. New project Menu VS 2017
Figure 3. Select Web API template.
  • open package manager console
  • Install this following package
Install-Package Microsoft.EntityFrameworkCore.SqlServer
  • To enable the reverse engineering to the existing database we have to install the following packages.
Install-Package Microsoft.EntityFrameworkCore.Tools –Pre
Install-Package Microsoft.EntityFrameworkCore.SqlServer.Design
Scaffold-DbContext “Server=your server name;Database=Login;Trusted_Connection=True;” Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
Figure 4. Model class Creation
Figure 5. Model class for User entity
Figure 6. Dapper Package in NuGet
Figure 7. Interface IUserDataProvider
Figure 8. UserDataProvider .cs
[Route(“api/[controller]”)]
Figure 9. UserController.cs
Figure 10. Default URL routing Logic
Figure 11. Result from get action
Figure 12. Result from get action by passing UserID
Figure 13. Update an user from PUT action and the Results from GET action
Figure 14. Delete user from DELETE action.
Figure 15. Create an user from POST action.
Figure 16. Results of the Database table

Summary

--

--

--

Senior Software Engineer in 99X Technology |Author in Better Programming

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Are libraries/frameworks an overkill?

Firebase Authentication with Flutter

Database Migration with Alibaba Cloud — Part 2

Concept explanation— How to EVM cross-chain? ETH <> BSC & CREATE2Deployer

How codeless test automation tools differ from Selenium?

Bringing the model of our robot to the simulation environment

Demystifying Apache Kafka Message Delivery Semantics: At-most-once & At-least-once &…

Example of Dropped Event Due to Disrupted Communication

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
Maheshi Gunarathne

Maheshi Gunarathne

Senior Software Engineer in 99X Technology |Author in Better Programming

More from Medium

How To Hire ASP Net MVC Developer

How to build a REST API with ASP.NET Web API

Inside ASP.NET Core 6 React Template

A Simple React Application in Visual Studio 2022