获取输出参数值 [英] Get output parameter value

查看:79
本文介绍了获取输出参数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在MVC项目中使用EF。在我的项目中,我需要使用存储过程。我的问题是在存储过程中使用输出参数。我不知道该怎么做

I'm using EF in my MVC project. In my project I need to use stored procedures. My problem is to use output parameter with stored procedures. I have no idea how to do that

推荐答案

在创建实体模型时,应确保包含存储过程。然后,为它们创建函数导入:

When you create your entity model, you should make sure that you include stored procedures. Then, create Function Imports for them:


  1. 在Visual Studio中打开实体模型

  2. 模型浏览器应在屏幕右侧打开

  3. 在模型浏览器中,您需要选择存储过程,然后单击添加函数导入以创建用于

  4. 将打开一个对话框以选择存储过程并返回类型

  1. Open your Entity Model in Visual Studio
  2. The Model Browser should open on the right side of the screen
  3. In the Model Browser, you need to select the stored procedure and click Add Function Import to create the function for the stored procedure.
  4. A dialog box will open to select the stored procedure and return type

就是这样。现在您可以在代码中使用它了。

That's it. Now you can use that in code.

using (MyEntities myContext = new MyEntities ())            
{                
   System.Data.Objects.ObjectParameter output = new System.Data.Objects.ObjectParameter("OutputParameterName", typeof(int));                
   myContext.GetCustomerCount(output);                
   Console.WriteLine(output.Value);            
}

这篇关于获取输出参数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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