如何在ADO.NET Entity Framework中运行存储过程?

时间:2021-09-12 02:16:15

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
Name nvarchar(50)
SurName nvarchar(50)

我的专栏:CustomerID PK ink名称nvarchar(50)SurName nvarchar(50)

1 个解决方案

#1


Here's an MSDN article about using sprocs in Entity Framework.

这是一篇关于在Entity Framework中使用sprocs的MSDN文章。

And another one.

另一个。

#1


Here's an MSDN article about using sprocs in Entity Framework.

这是一篇关于在Entity Framework中使用sprocs的MSDN文章。

And another one.

另一个。