How to call Stored Procedure in Entity Framework 6 (Code-First)?

前端 未结 21 2349
滥情空心
滥情空心 2020-11-22 05:04

I am very new to Entity Framework 6 and I want to implement stored procedures in my project. I have a stored procedure as follows:

ALTER PROCEDURE [dbo].[ins         


        
21条回答
  •  轮回少年
    2020-11-22 05:45

    You can pass parameters to sp_GetById and fetch the results either in ToList() or FirstOrDefault();

    var param  = new SqlParameter("@id", 106);
    var result = dbContext
                   .Database
                   .SqlQuery("dbo.sp_GetById @id", param)
                   .FirstOrDefault();
    

提交回复
热议问题