MVC 5 Entity Framework 6 Execute Stored Procedure

后端 未结 2 855
迷失自我
迷失自我 2021-02-06 15:46

I\'m stuck. I have an existing application with an extremely large database and extensive library of stored procedures and functions. All I want to do is use a DbContext to ex

2条回答
  •  耶瑟儿~
    2021-02-06 15:53

    Wow, it seems right after I give up, I somehow stumble upon the answer. I found a FANTASTIC post about executing stored procedures and after reading up, this was my solution:

    var contacts = db.Database.SqlQuery("Contact_Search @LastName, @FirstName",
    

    So, many thanks to Anuraj for his excellent post! The key to my solution was to first use SqlQuery instead of ExecuteSqlCommand, and also to execute the method mapping to my entity model (Contact).

提交回复
热议问题