As you know day by day Dapper Micro ORM increasing popularity among developers because of its speed and less code. So in this article explains how to call stored procedure with Dapper.
Suppose you have following Model class
In the above functionSuppose you have following Model class
public class EmpModel { [Required(ErrorMessage = "First name is required.")] public string Name { get; set; } [Required(ErrorMessage = "City is required.")] public string City { get; set; } [Required(ErrorMessage = "Address is required.")] public string Address { get; set; } }Now consider following stored procedure we have
Create procedure [dbo].[AddNewEmpDetails] ( @Name varchar (50), @City varchar (50), @Address varchar (50) ) as begin Insert into Employee values(@Name,@City,@Address) EndNow following is the function which is used to pass above stored procedure to Dapper
public void AddEmployee(EmpModel objEmp) { //Passing stored procedure using Dapper.NET connection(); con.Execute("AddNewEmpDetails", objEmp, commandType: CommandType.StoredProcedure); }
- Connection() is the method which contains the connection string .
- Con is the SqlConnection class object.
- AddNewEmpDetails is the stored procedure.
- ObjEmp is the object of model class
I hope this article is useful for all readers. If you have any suggestion then please contact me.
Please read my previous article to understand the basics about MVC.
- ActionResult in ASP.NET MVC.
- Creating an ASP.NET MVC Application.
- CRUD Operations In ASP.NET MVC 5 Using ADO.NET
- Convert DataTable To Generic List In ASP.NET MVC .
- Show Confirm Alert Box on ActionLink Click In ASP.NET MVC.
- Convert DataTable To Generic List Using LINQ In ASP.NET MVC.
- How to Change ActionLink Text Color In ASP.NET MVC .
- How to Call Another Controller View Using ActionLink In ASP.NET MVC .
- Convert DataTable To Generic List Using AsEnumerable In ASP.NET MVC .
Post a Comment