How to use stored procedure in ADO.NET Entity Framework?
My Table : MyCustomer
Columns:
CustomerID PK int
Name nvarchar(50)
SurName nvarchar(50)
My stored procedure
ALTER procedure [dbo].[proc_MyCustomerAdd]
(@Name nvarchar(50),
@SurName nvarchar(50)
)
as
begin
insert into dbo.MyCustomer([Name], SurName) values(@name,@surname)
end
My C# code
private void btnSave_Click(object sender, EventArgs e)
{
entityContext.MyCustomerAdd(textName.Text.Trim(), textSurName.Text.Trim());
entityContext.SaveChanges();
}
The error:
The data reader is incompatible with the specified 'TestAdonetEntity2Model.MyCustomer'. A member of the type, 'CustomerID', does not have a corresponding column in the data reader with the same name.
Error occured below the last code line (call to ExecuteFunction):
global::System.Data.Objects.ObjectParameter surNameParameter;
if ((surName != null))
{
surNameParameter = new global::System.Data.Objects.ObjectParameter("SurName", surName);
}
else
{
surNameParameter = new global::System.Data.Objects.ObjectParameter("SurName", typeof(string));
}
<b>return base.ExecuteFunction<MyCustomer>("MyCustomerAdd", nameParameter, surNameParameter);</b>
Added is ok. Every added process is ok. But after editing, above error occurs.