I did some research in internet to know how to execute Stored Procedure using Entity Framework code-first approach. But i did not get any clear idea. Everybody is telling their own way of executing SP. In some blogs they have mentioned to execute in the following way and in other they have mentioned in a traditional ADO.NET way.
DbContext.Database.SqlQuery<ProcedureResult>("sp_TestProcedure @param1, @param2",param1val, param2value);
please let me know what is the appropriate way to execute SP. I am using MVC3, Entity FW code-first approach. Thanx
I had the same question several weeks ago and updated my answer with the solution I wound up using. Have since expanded the use a bit and am relatively happy with how clean the solution is. The results I needed would not map to my entities, so the fact that I am not returning Entities directly was not a loss for me, but may be annoying in your case if that is your intent.
See here: Code-First Entity Framework w/ Stored Procedure returning results from complex Full-text Searches