Introduction to Dapper.NET ORM in ASP.NET 5
February 22, 2015 by Anuraj
.Net .Net 3.0 / 3.5 .Net 4.0 ASP.Net ASP.Net MVC CodeProject Windows Forms
Dapper.NET is an open source, high performance Micro-ORM supporting Sql Server, MySQL, Sqlite, SqlCE, Firebird etc, from Stack Overflow team. Drapper provides extension methods for IDbConnection, so you require an instance of IDbConnection to use Dapper. To use Dapper, you need to include Dapper in the project.json file. In this post I am using Repository pattern and injecting the repository to the controller via constructor injection.
Here is the project.json file, the EntityFramework.SqlServer reference is required to use IDbConnection interface.
Here is the constructor of the respository class. In this I am creating the instance of SqlConnection.
Dapper extends the IDbConnection with Query method, which you can use to execute a query and map the result to a strongly typed object or list of objects.
You can use Execute method to execute DML queries as well to the Database.
Dapper also supports Stored Procedures as well. You need to provide the command type parameter.
You can use Dapper in ASP.NET or any .net applications, for that you need to include the Dapper nuget reference. You can find more details about Dapper from Dapper wiki
Happy Programming :)
Copyright © 2024 Anuraj. Blog content licensed under the Creative Commons CC BY 2.5 | Unless otherwise stated or granted, code samples licensed under the MIT license. This is a personal blog. The opinions expressed here represent my own and not those of my employer. Powered by Jekyll. Hosted with ❤ by GitHub