-
Notifications
You must be signed in to change notification settings - Fork 350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OData.Client DataServiceContext BulkUpdate() Always Uses Protocol Version 4.01 #3004
OData.Client DataServiceContext BulkUpdate() Always Uses Protocol Version 4.01 #3004
Comments
@AlpineJBoehnen the Bulk Updates feature is only supported in 4.01, that's why the client forces that 4.01 header when making bulk update requests. The format that we use to serialize bulk operation requests and responses is based on features only support in the 4.01 protocol. For example, the 4.01 protocol defines syntax for specifying changes to related/nested entities like so: {
"@type": "#Northwind.Manager",
"FirstName": "Patricia",
"DirectReports@delta": [
{
"@removed": {
"reason": "deleted"
},
"@id": "Employees(3)"
},
{
"@removed": {
"reason": "changed"
},
"@id": "Employees(4)"
},
{
"@id": "Employees(5)"
},
{
"@id": "Employees(6)",
"LastName": "Smith"
},
{
"FirstName": "Suzanne",
"LastName": "Brown"
}
]
} But this format is not supported in 4.0. 4.0 does support linking to entities using {
"@odata.type":"#Northwind.Manager",
"ID": 1,
"FirstName": "Pat",
"LastName": "Griswold",
"[email protected]": [
"http://host/service/Employees(5)",
"http://host/service/Employees(6)"
]
} But it's very limited and is not sufficient to support bulk updates. For more info, see: https://docs.oasis-open.org/odata/odata/v4.01/odata-v4.01-part1-protocol.html#sec_LinktoRelatedEntitiesWhenCreatinganE |
Thank you for the explanation. Exploring the spec further I can see this is correct client behavior. I have created a related issue for Microsoft.AspNetCore.OData to seek assistance on the server implementation. |
@AlpineJBoehnen this blog post demonstrates how to use bulk ops on the server with Microsoft.AspNetCore.OData https://devblogs.microsoft.com/odata/bulk-operations-support-in-odata-web-api/, the blog post is based on the 7.x version, but it should work for 8 as well (@ElizabethOkerio correct me if I'm wrong) |
@habbes I may be wrong, but I don't believe that blog post applies to Microsoft.AspNetCore.OData 8.x because it is no longer considered OData Web API? Perhaps bulk update is simply one of the features being referred to by this article when it says:
Any other insight would be greatly appreciated, I am hoping to continue development with 8.x opposed to 7.x. If bulk update is not available in 8.x yet is there a plan to add it? Looking forward to hearing your insight on this as well @ElizabethOkerio |
The feature is supported in 8.x. Look at some of these tests here: https://github.com/ElizabethOkerio/AspNetCoreOData/blob/1a0edd4cd9bae3ecc5cf34fe866d623515d935d1/test/Microsoft.AspNetCore.OData.E2E.Tests/BulkOperation/EmployeesController.cs . The issue you're experiencing today could be a bug that we're currently investigating. |
@ElizabethOkerio Thanks for that example. I will experiment some more and see what I can deduce. Might be worth mentioning, when I use the following code in those tests the PatchEmployees DeltaSet parameter is null and the tests fail. HttpClient client = CreateClient();
client.DefaultRequestHeaders.Add("OData-Version", "4.01"); |
In Microsoft.OData.Client 7.21.3 the
Microsoft.OData.Client.DataService.Context.BulkUpdate()
method appears to force the OData-Version header to 4.01 regardless of themaxProtocolVersion
provided to the DataServiceContext constructor. I am using Microsoft.AspNetCore.OData 8.2.5 on my server, and out of the box it cannot deal with this protocol of OData for bulk updates (Specifically theDeltaSet<T>
parameter of my entity set patch action is always null). In Postman if I send an identical request as the client to the server but with the OData-Version header set to 4.0 the server handles this without issue. My questions are as follows:I should also note that I am using OData Connected Service on my client for code generation, but I am not sure this is relevant.
Assemblies affected
Microsoft.OData.Client 7.21.3
Microsoft.AspNetCore.OData 8.2.5
Reproduce steps
I implemented Sample Request 1 from the OData Client Bulk Update Operations examples on my client.
And implemented an endpoint on my server to "patch a collection of entities" from this Microsoft.AspNetCore.OData tutorial.
Note: I modified the client example to work with the Shape, Circle, Rectangle models from the server example.
Client code:
Server code:
Expected result
The
BulkUpdate()
method would succeed on the client, and theDeltaSet<T>
parameter on the server would not be null when the action executes.Actual result
The
DeltaSet<T>
parameter is null when the server action executes, meaning the server returns BadRequest and the client update operation fails.The text was updated successfully, but these errors were encountered: