【问题标题】:Calling insert stored procedure using entity framework that has return parameter使用具有返回参数的实体框架调用插入存储过程
【发布时间】:2017-03-15 18:24:11
【问题描述】:

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

我不确定如何返回 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();
            }

【问题讨论】:

    标签: asp.net-web-api entity-framework-6


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-07
      • 2016-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多