简体   繁体   English

如何在ADO.NET实体框架中无错误地调用存储过程?

[英]How to call stored procedure without error in ADO.NET Entity Framework?

How do I call a stored procedure without error in ADO.NET Entity Framework? 如何在ADO.NET实体框架中调用没有错误的存储过程? 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'. 数据读取器与指定的“ NetTanitimTestModel.Categories”不兼容。 A member of the type, 'ID', does not have a corresponding column in the data reader with the same name. 类型“ ID”的成员在数据读取器中没有具有相同名称的对应列。

 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 我有3表的类别表:PARENTID,Category,Date

Mitch Wheat gave you the answer. 米奇·麦特(Mitch Wheat)给了你答案。 You're trying to use the ID column, but the table has a PARENTID column. 您正在尝试使用ID列,但是该表具有PARENTID列。

It looks as if your EF data model and your database are not in sync anymore. 看来您的EF数据模型和您的数据库不再同步。 It seems as if your "Categories" object in the EF data model has an "ID" field but the table does not. 似乎您在EF数据模型中的“类别”对象具有“ ID”字段,但表却没有。

I would update the EF data model from the database and see if that fixes the problem. 我将从数据库更新EF数据模型,看看是否可以解决问题。 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. 为此,打开EDMX设计器,然后在设计图面上的空白处单击鼠标右键,然后选择“从数据库更新模型”选项。 That should bring the two worlds back into sync. 那应该使两个世界重新同步。

Marc

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

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