I am writing a logic for inserting record using Entity Framework store procedure that will return an int parameter that is TeamId. I have created the function import for the store procedure. Please see the screenshot below
I am not sure how to return the int parameter. Please see the code below
DataAccess layer
public int InsertTeam(string countryCode, string teamName, string TeamDescription, string createdBy, char isActive)
{
using (var mcrContext = new MCREntities())
{
return (from team in mcrContext.InsertTeam(countryCode, teamName, TeamDescription, createdBy, true)
select
{
}).ToList();
}
What you get back from the procedure is an ObjectResult<T>
. In your situation simply do:
public int InsertTeam(string countryCode, string teamName, string TeamDescription, string createdBy, char isActive)
{
using (var mcrContext = new MCREntities())
{
var result = mcrContext.InsertTeam(countryCode, teamName, TeamDescription, createdBy, true);
return result.Single().Value;
}
}