How to call Stored Procedures with EntityFramework?

前端 未结 7 1316
青春惊慌失措
青春惊慌失措 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

    You have use the SqlQuery function and indicate the entity to mapping the result.

    I send an example as to perform this:

    var oficio= new SqlParameter
    {
        ParameterName = "pOficio",
        Value = "0001"
    };
    
    using (var dc = new PCMContext())
    {
        return dc.Database
                 .SqlQuery("exec SP_GET_REPORTE @pOficio",
                                            oficio)
                 .ToList();
    }
    

提交回复
热议问题