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 i开发者_运维问答s 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
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
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));
精彩评论