How to create Store Procedure using Code First Entity Framework

                  How to create Store Procedure using Code First Entity Framework




To add Store procedure  using code first Entity Framework .First we have add migration --any
 from Package manager console.

Steps

   
   1. Select to Tools in visual studio

   2.In tools select NuGet Pacakage Manager

   3. In NuGet Pacakage Manager select select Package mange console.



Add a new Migration and in this migration add
 

   using System;
  using Microsoft.EntityFrameworkCore.Migrations;

   namespace LMSApiSol.Migrations
{
    public partial class Data : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.Sql(@"create Proc [dbo].[Sp_Getall Employeeinfo]    

  as      
  Begin      
  select * from Employee
end
  ");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
       
        }
    }
   }



Now we will run Command update-Database in Package  manager console;
Store procedure will be added successfully

No comments:

Post a Comment