输出参数与实体框架 [英] Output parameter with Entity Framework

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

问题描述

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

解决方案

当您创建实体模型时,应确保包含存储过程。然后,为它们创建功能导入:


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

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

  3. 在模型浏览器中,您需要选择存储过程,然后单击添加功能导入来创建功能存储过程。

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



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


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. 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天全站免登陆