1

I need to call SP from Entity Framework, with DB first approach. Below is the code for it. But i am facing error.

"The stored procedure or function 'XXXXXXX' does not have a return type. ExecuteFunction only supports stored procedures and functions that have a return type."

var searchFieldParameter = searchField != null ?
            new ObjectParameter("SearchField", searchField) :
            new ObjectParameter("SearchField", typeof(string));

var searchTextParameter = searchText != null ?
            new ObjectParameter("SearchText", searchText) :
            new ObjectParameter("SearchText", typeof(string));

return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction<ReasonCode>("XXXXXXX", searchFieldParameter, searchTextParameter);
Umair Akbar
  • 578
  • 5
  • 11
  • Does this answer your question? [Error calling Stored Procedures from EntityFramework](https://stackoverflow.com/questions/30216830/error-calling-stored-procedures-from-entityframework) – d219 Oct 17 '20 at 20:04

1 Answers1

1

I got the answer to my question.Below code can be used to call SP from EF

var searchFieldParameter = searchField != null ?
            new SqlParameter("SearchField", searchField) :
            new SqlParameter("SearchField", typeof(string));

        var searchTextParameter = searchText != null ?
            new SqlParameter("SearchText", searchText) :
            new SqlParameter("SearchText", typeof(string));

        return ((IObjectContextAdapter)this).ObjectContext.ExecuteStoreQuery<ReasonCode>("exec Reason_Codes_Search_SP @SearchField, @SearchText ", searchFieldParameter, searchTextParameter);
Umair Akbar
  • 578
  • 5
  • 11