Generating and accessing stored procedures using Entity framework core

前端 未结 5 2109
一向
一向 2020-12-28 17:50

I am implementing Asp.Net core Web API , entity framework core, database first approach using Visual Studio 2017. I have managed to generate the context and class files base

5条回答
  •  鱼传尺愫
    2020-12-28 18:15

    The workaround we use in EF Core to execute stored procedures to get the data is by using FromSql method and you can execute stored procedure this way:

    List employees = dbcontext.Employee
                        .FromSql("GetAllEmployees").ToList();
    

    But for Create, Update, and Delete, we use ExecuteSqlCommand like the one below:

    var employee = "Harold Javier";
    dbcontext.Employee
               .ExecuteSqlCommand("InsertEmployee @emp", employee);
    

提交回复
热议问题