Here In this document I will explain the following topics:

Let's start.

Mapping Stored Procedures

I am taking 2 classes to show how to map these things.

  1. public class StudentStore
  2. {
  3. [Key]
  4. public int STUDENTID { get; set; }
  5. public string STUDENTName { get; set; }
  6. public string ROLLNO { get; set; }
  7. public string COURSE { get; set; }
  8. }
  9. public class Deparmentstore
  10. {
  11. [Key]
  12. public int DeparmentID {get ;set;}
  13. public string DeparmentName { get; set; }
  14. }
The normal way of writing an inline query with parameters in dapper is:

Here in the Insertstudent method above I created DynamicParameters and assiged values to the parameters after with showing how to get parameterdirection.output and return a value from it. It's simple; if go throug this code then you will get it in one shot.

How to Map multiple records from a single Stored Procedure

QueryMultiple : That is defined for compound SQL statements that return multiple result sets.

Here in Multiple Records reading I have created Stored Procedures that return 2 tables and that use Multi.Read.

We can get all the records of a student in a studentStore class and Department in Deparmentstore .

On the other hand, you are trying to get two different columns from a single result set, so you should just use the normal Query method as in the following:

  1. ALTER PROCEDURE Usp_GetRec
  2. AS
  3. BEGIN
  4. SELECT *
  5. FROM [Student]
  6. SELECT *
  7. FROM Department
  8. END
How to get Records from Stored Procedures
  1. var employees = Con.Query<StudentStore>("Usp_getstudent", commandType: CommandType.StoredProcedure);
Here is a simple way to get a value return from a Stored Procedure.