Asp.net web api 使用具有返回参数的实体框架调用insert存储过程

Asp.net web api 使用具有返回参数的实体框架调用insert存储过程,asp.net-web-api,entity-framework-6,Asp.net Web Api,Entity Framework 6,我正在编写一个使用实体框架存储过程插入记录的逻辑,该过程将返回一个名为TeamId的int参数。我已经为存储过程创建了函数导入。请看下面的截图 我不知道如何返回int参数。请参阅下面的代码 数据访问层 public int InsertTeam(string countryCode, string teamName, string TeamDescription, string createdBy, char isActive) { using (var

我正在编写一个使用实体框架存储过程插入记录的逻辑,该过程将返回一个名为TeamId的int参数。我已经为存储过程创建了函数导入。请看下面的截图

我不知道如何返回int参数。请参阅下面的代码

数据访问层

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();
            }

您从该过程中得到的是一个
ObjectResult
。在您的情况下,只需执行以下操作:

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;
    }
}