Calling insert stored procedure using entity framework that has return parameter

asp.net-web-api entity-framework-6

Question

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

enter image description here

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();
            }
1
0
3/13/2017 4:04:06 PM

Popular Answer

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;
    }
}
0
3/15/2017 10:24:11 AM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow