为什么我会得到“具有身份“ReturnValue”的成员?元数据集合中不存在”错误?

发布于 2024-10-05 01:36:00 字数 1247 浏览 7 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

玩套路吗 2024-10-12 01:36:01

身份密钥区分大小写。请检查它是否正确作为参数提供。
例子:

context.mCustomersReference.EntityKey = new EntityKey("BulkEntities.CustomerSet", "CustomerId", Convert.ToInt64(id));

Identity Key is Case Sensitive. Pls check is it properly provided as Parameter.
Example:

context.mCustomersReference.EntityKey = new EntityKey("BulkEntities.CustomerSet", "CustomerId", Convert.ToInt64(id));
甜心 2024-10-12 01:36:00

我假设这是错误行

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)

现在第一个参数是“Nothing”,我假设它应该是存储过程的“返回值”(您是否使用存储过程?)。

如果您实际上使用的是诸如 @ID int output 之类的存储过程,那么您的代码中需要一个适当的输出参数,

        Dim IDOut As Integer
        Dim wo As WorkOrder = MyApp.WorkOrder.CreateWorkOrder(IDOut, 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)

        ''# Do crap with IDOut like redirect to http://example.com?workorder=[IDOut]

但正如我在评论中所说,您最好使用 LINQ SQL 并避免使用存储过程进行简单插入。

类似的东西

    Public Sub GenerateWorkOrder()

        Dim workOrder As New WorkOrder
        With workOrder
             .somestringParameter1 = "the parameter"
             .someintegerParameter1 = 5
             ''# etc
        End With

        CreateWorkOrder(workOrder)
        SubmitChanges()

    End Sub


    Public Sub CreateWorkOrder(ByVal workOrder As WorkOrder)
        ''# dc is simply the DataContext
        dc.WorkOrders.InsertOnSubmit(workOrder)
    End Sub

    Public Sub SubmitChanges()
        dc.SubmitChanges()
    End Sub

I'm assuming that this is the erroring line

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)

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 code

        Dim IDOut As Integer
        Dim wo As WorkOrder = MyApp.WorkOrder.CreateWorkOrder(IDOut, 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)

        ''# Do crap with IDOut like redirect to http://example.com?workorder=[IDOut]

But 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

    Public Sub GenerateWorkOrder()

        Dim workOrder As New WorkOrder
        With workOrder
             .somestringParameter1 = "the parameter"
             .someintegerParameter1 = 5
             ''# etc
        End With

        CreateWorkOrder(workOrder)
        SubmitChanges()

    End Sub


    Public Sub CreateWorkOrder(ByVal workOrder As WorkOrder)
        ''# dc is simply the DataContext
        dc.WorkOrders.InsertOnSubmit(workOrder)
    End Sub

    Public Sub SubmitChanges()
        dc.SubmitChanges()
    End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文