How to Send parameters in Store Procedure using Code First Entity framework

               How to Send  parameters  in Store Procedure using Code First Entity framework



There are different ways to send parameter Store procedure using  in Code first  Entity frame work.


1.When you have only one parameter





   public dynamic Getmonths (int EmployeeID)
        {
      var GetMonth = _context.Sp_GetAllMonths.FromSqlRaw("[dbo].  [Sp_Getallmonth]      @EmployeeID=" + EmployeeID + "").ToList();
           
            return GetMonth;
        }


  2 .When you have two parameter (this is the best way to send  parameter in the store procedure)



     public dynamic GetSlips(string SalaryMonth, int EmployeeID)
        {
            dynamic EmployeeIDs = EmployeeID;
            string SalaryMonths = SalaryMonth.ToString();

            var Getdata = _context.SP_SalarySlip.FromSqlRaw("dbo.SP_SalarySlipbymonths     @p0 ,@p1 ",      parameters: new[] { EmployeeIDs , SalaryMonths }).ToList();
            return Getdata ;
        }

No comments:

Post a Comment