How to call Stored Procedures with EntityFramework?

前端 未结 7 1333
青春惊慌失措
青春惊慌失措 2020-12-01 02:03

I have generated an EF4 Model from a MySQL database and I have included both StoredProcedures and Tables.

I know how to make regular instert/update/fetch/delete oper

7条回答
  •  醉酒成梦
    2020-12-01 02:44

    One way is to use the Database property off the DbContext:

    SqlParameter param1 = new SqlParameter("@firstName", "Frank");
    SqlParameter  param2 = new SqlParameter("@lastName", "Borland");
    context.Database.ExecuteSqlCommand("sp_MyStoredProc @firstName, @lastName", 
                                  param1, param2);
    

    EF5 definitely supports that.

提交回复
热议问题