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

前端 未结 21 2550
滥情空心
滥情空心 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:51

    You are using MapToStoredProcedures() which indicates that you are mapping your entities to stored procedures, when doing this you need to let go of the fact that there is a stored procedure and use the context as normal. Something like this (written into the browser so not tested)

    using(MyContext context = new MyContext())
    {
        Department department = new Department()
        {
            Name = txtDepartment.text.trim()
        };
        context.Set().Add(department);
    }
    

    If all you really trying to do is call a stored procedure directly then use SqlQuery

提交回复
热议问题