通过实体框架来自存储过程的标量值 [英] Scalar Value from stored procedure via Entity Framework

查看:56
本文介绍了通过实体框架来自存储过程的标量值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了几篇类似的文章: http://devtoolshed.com/using-stored-procedures-entity-framework-scalar-return-values

I have found a few articles like this one: http://devtoolshed.com/using-stored-procedures-entity-framework-scalar-return-values

但是,当我采取步骤为int32标量创建函数导入时,会生成以下内容:

Yet when I take the step to create a function import for a int32 scalar, this is what gets generated:

 public ObjectResult<Nullable<global::System.Int32>> MyStoredProcedure(Nullable<global::System.Int32> orderId)
    {
        ObjectParameter orderIdParameter;
        if (orderId.HasValue)
        {
            orderIdParameter = new ObjectParameter("OrderId", orderId);
        }
        else
        {
            orderIdParameter = new ObjectParameter("OrderId", typeof(global::System.Int32));
        }

        return base.ExecuteFunction<Nullable<global::System.Int32>>("MyStoredProcedure", orderIdParameter);
    }

我可以以此调用该过程,但不能使用底层标量:

I am able to call the procedure with this, but am not able to get to the underlying scalar:

ObjectResult< int?>结果= myEntities.MyProcedure(orderId);

在我看到的代码示例中,我应该得到 context.MyProcedure().SingleOrDefault().

In the code examples I have seen, I should get context.MyProcedure().SingleOrDefault().

推荐答案

尝试一下:

int? result = myEntities.MyProcedure(orderId).FirstOrDefault();

这篇关于通过实体框架来自存储过程的标量值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆