How do I call a stored procedure without error in ADO.NET Entity Framework? If I use the code below, I get an error:
adminNameContext.AddItemCategory(12, "ggf", DateTime.Now);
Error:
The data reader is incompatible with the specified ‘NetTanitimTestModel.Categories’. A member of the type, ‘ID’, does not have a corresponding column in the data reader with the same name.
ALTER procedure [dbo].[sp_AddItemCategory]
(
@item int,
@category nvarchar(50),
@date smalldatetime
)
as
begin
if(@item=-1)
begin
insert into Categories(PARENTID,Category,Date) values(null,@category,@date)
end
else
begin
insert into Categories(PARENTID,Category,Date) values(@item,@category,@date)
end
end
i have Categories table which has got 3 columns: PARENTID,Category,Date
It looks as if your EF data model and your database are not in sync anymore. It seems as if your “Categories” object in the EF data model has an “ID” field but the table does not.
I would update the EF data model from the database and see if that fixes the problem. To do this, open up the EDMX designer and right click on an empty spot in the design surface, and pick the “Update model from database” option. That should bring the two worlds back into sync.
Marc