简体   繁体   English

如何在ADO.NET实体框架中运行存储过程?

[英]How to run stored procedure in ADO.NET Entity Framework?

I added this code below: 我在下面添加了以下代码:

public partial class Form1 : Form
{
    TestAdonetEntity2Entities entityContext;
    public Form1()
    {
        InitializeComponent();
        entityContext = new TestAdonetEntity2Entities();
    }

    private void Form1_Load(object sender, EventArgs e)
    {
       dataGridView1.DataSource =  entityContext.SelectMyCustomer();
    }
}

But this code will cause an error: 但是此代码将导致错误:

public global::System.Data.Objects.ObjectResult<MyCustomer> SelectMyCustomer()
{
     return base.ExecuteFunction<MyCustomer>("SelectMyCustomer");
}

The error is: 错误是:

An error occurred while executing the command definition. 执行命令定义时发生错误。 See the inner exception for details. 有关详细信息,请参见内部异常。

My stored procedure...: 我的存储过程...:

ALTER procedure [dbo].[proc_MyCustomer]
as
begin
  select * from  dbo.MyStuffs
end

My Columns: CustomerID PK ink 我的专栏:CustomerID PK墨水
Name nvarchar(50) 名称nvarchar(50)
SurName nvarchar(50) 姓nvarchar(50)

Here's an MSDN article about using sprocs in Entity Framework. 这是有关在Entity Framework中使用存储过程的MSDN文章

And another one. 还有一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM