16 February 2017

Calling Stored Procedure from Entity Framework

Let's say we have a simple stored procedure that displays all the records from tbl_Sales table:

CREATE PROCEDURE [dbo].[sp_DisplayRecord]
AS
BEGIN
    SELECT * FROM tbl_Sales
END


Assuming that ctx is our DbContext, we can call the stored procedure from EF using the following command:

var query = ctx.Database.SqlQuery<tbl_Sales>("sp_DisplayRecord").AsEnumerable();

No comments:

Post a Comment