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

时间:2009-06-13 18:04:48

标签: c# .net linq-to-sql entity-framework

我在下面添加了以下代码:

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

但是这段代码会导致错误:

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

错误是:

  

执行时出错   命令定义。看到内心   细节例外。

我的存储过程......:

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

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

1 个答案:

答案 0 :(得分:1)

这是关于在Entity Framework中使用sprocs的MSDN article

another one.