为什么我会得到“具有身份“ReturnValue”的成员?元数据集合中不存在”错误?
我在 Visual Studio 中设置 OData 提供程序。我收到的错误实际上与 OData 方面没有任何关系。
我的 ado 实体数据模型中有一个表类型,每当我尝试将记录插入到该表中时,都会收到以下错误:
{“元数据集合中不存在身份为“ReturnValue”的成员。 参数名称:身份”}
这是堆栈跟踪:
在 System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager,IEntityAdapter 适配器) 在System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager实体缓存) 在 System.Data.Objects.ObjectContext.SaveChanges(SaveOptions 选项) 在 System.Data.Objects.ObjectContext.SaveChanges() 在 OData.CreateWorkOrder(Int32 CreatedByContactID) 中 D:\Web\OData.svc.vb:第 31 行
有人听说过这个错误吗?我可以很好地插入到任何其他表中,但似乎 ado 实体数据模型不想使用这个表。
提前致谢
''# this comment is just here because the code formatter doesn't play nice otherwise.
<WebGet()> _
Public Function CreateWorkOrder(ByVal CreatedByContactID As Integer) As WorkOrder
Dim x As New MyAppEntities
Dim wo As WorkOrder = MyApp.WorkOrder.CreateWorkOrder(Nothing, 100, 4, False, DateTime.Now, False, 0, 1, 0, 0, 0, 0, 0, 0, False, 0, 0, 0, False, CreatedByContactID, DateTime.Now, 1, DateTime.Now)
x.AddToWorkOrders(wo)
x.SaveChanges()
Return wo
End Function
Im setting up an OData provider in visual studio. The error that im receiving really doesnt have anything to do with OData side of things.
I have a table type in my ado entity data model and whenever I try to insert a record into this table i get the following error:
{"The member with identity 'ReturnValue' does not exist in the metadata collection.
Parameter name: identity"}
This is the stacktrace:
at System.Data.Mapping.Update.Internal.UpdateTranslator.Update(IEntityStateManager stateManager, IEntityAdapter adapter)
at System.Data.EntityClient.EntityAdapter.Update(IEntityStateManager entityCache)
at System.Data.Objects.ObjectContext.SaveChanges(SaveOptions options)
at System.Data.Objects.ObjectContext.SaveChanges()
at OData.CreateWorkOrder(Int32 CreatedByContactID) in
D:\Web\OData.svc.vb:line 31
Has anyone heard of this error? I can insert fine into any other table it just seems to be this one table that the ado entity data model doesnt want to play with.
Thanks in advance
''# this comment is just here because the code formatter doesn't play nice otherwise.
<WebGet()> _
Public Function CreateWorkOrder(ByVal CreatedByContactID As Integer) As WorkOrder
Dim x As New MyAppEntities
Dim wo As WorkOrder = MyApp.WorkOrder.CreateWorkOrder(Nothing, 100, 4, False, DateTime.Now, False, 0, 1, 0, 0, 0, 0, 0, 0, False, 0, 0, 0, False, CreatedByContactID, DateTime.Now, 1, DateTime.Now)
x.AddToWorkOrders(wo)
x.SaveChanges()
Return wo
End Function
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
身份密钥区分大小写。请检查它是否正确作为参数提供。
例子:
Identity Key is Case Sensitive. Pls check is it properly provided as Parameter.
Example:
我假设这是错误行
现在第一个参数是“Nothing”,我假设它应该是存储过程的“返回值”(您是否使用存储过程?)。
如果您实际上使用的是诸如
@ID int output
之类的存储过程,那么您的代码中需要一个适当的输出参数,但正如我在评论中所说,您最好使用 LINQ SQL 并避免使用存储过程进行简单插入。
类似的东西
I'm assuming that this is the erroring line
Now the first parameter is "Nothing" whereby I'm assuming it's supposed to the the "Return Value" of a stored procedure (are you using stored procedures?).
If you are in fact using a stored procedure with something like
@ID int output
, then you need a proper output parameter in your codeBut as I said in my comment, you'd be better of using LINQ to SQL and avoiding Stored Procedures for simple inserts.
Something along the lines of