-
Notifications
You must be signed in to change notification settings - Fork 352
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 V4 client is not working with "deep insert" aka parent / child insert #736
Comments
What is the status on this? I've tested this with the Microsoft.OData.Client (7.4.0-beta2) and it still doesn't work for me. When using Postman to post a request containing parent and child objects, deeply inserting works nicely. With the OData client, the children are not included in the request. |
This does not look to be fixed BUT here is a "partial" class of the OData client "Container" class that does the trick.
Then just call it like the following |
@ImGonaRot Thanks for your quick reply. I was thinking about hand-coding something like this myself. However, the question is still whether something that is required by the standard could make it into the library sooner or later. I am looking at OData and this library because I wanted to stop writing and testing my own code for these things. |
I've now created a simple, working example, using RestSharp (106.2.0) and Newtonsoft.Json (10.0.3) in conjunction with the entity classes created by the OData Connected Service (Version 0.3.0) extension. Metadata (Simplified)
The real EntityContainer defines other entity sets. However, the Event entity type is contained and therefore not directly accessible from the service root. The same is true for the EventAttribute entities. Those are contained in events and it makes sense to use deep inserts to create them together with the containing event. RestSharp-based Container
I've omitted the PostEventAsync method for brevity. Using the RestSharp-based Container
ThoughtsIt was very easy to create the RestSharp-based container and make it work right away. The event and its two attributes are inserted in the database as expected. Therefore, the question is how hard it would be to make the OData Client do the same thing. But maybe I am also not using the generated classes correctly. My problem there is that the documentation only covers the most basic examples and it is somewhat hard to figure out more advanced usage scenarios. Whatever I tried did not work. |
Json serialization doesn't work fine with Edm types. For example, Edm.Date is serialized: Does anyone know a way to serialize the entity with EDM types correctly? |
I share my serializer settings fixed for EDM types and other fix: ` public static string ToJson (this BaseEntityType entity) { public static class JsonConvertersCustom { public class EdmDateConverter : JsonConverter { public override void WriteJson (JsonWriter writer, Date value, JsonSerializer serializer) public class EdmDateNullableConverter : JsonConverter<Date?> { public override void WriteJson (JsonWriter writer, Date? value, JsonSerializer serializer) |
I am following the issue here. Is there any update on this? |
@ThomasBarnekow @mukesh-shobhit Looking into the issue. @ImGonaRot Should the right semantics for deep insert be
So in flight the JSON would look like
|
This is exactly what we expecting, but I am following the pattern you suggesting and deep insert does not work. I have:
and client code generated with: |
It's been several years now. Is this completely dead in the water? |
@marabooy I am experiencing the same issue with the latest Microsoft.AspNetCore.OData package (7.5.6) and ODataConnectedService (0.12.1). It has passed a year since your last reply, are there any updates on this ? Just to understand if this issue will be solved or not, because this jeopardizes the usability of OData since in almost every project you need to insert/update entities with related ones. |
@fededim The issue is currently being worked on so it can be supported across our tooling. |
@marabooy Ok, is it possible to have a timeframe ? Just to understand if its resolution goes on for months or on another year. |
@fededim I really can't give you a timeline for the whole delivery but you may see some of the pieces ship with some of our expected releases sometime through the year which will be linked to this work item when they are out of draft status :). |
@marabooy I'll hope for the best. Just a note: besides "deep insert" you should also address the "deep update" functionality of OData since they are both important for every project. |
@marabooy As a suggestion, my thought is that there be a SaveChangesOptions.IncludeChildren when calling SaveChanges.
|
Hi guys |
Hi guys Does anyone know if the change just addresses updates? Any possibility that it works for inserts as well? |
This feature would be very useful. When will it be included ? Thanks |
Any word on Deep updates and inserts? Looks like there was a PR for Updates at any rate.... |
Hey everyone, |
any news?. Thanks |
There is on-going work to support this and that is being tracked. |
@ElizabethOkerio Cool, can you link to that? Or is there some other way to subscribe to something, so we can know, when this feature is available? |
I know batching is working but the OData client is not working when inserting a new parent and new child at the same time.
Ex.
`Parent p = new Parent();
// set parent properties
Child c = new Child();
// set child properties
c.Parent = p;
p.Children.Add(c);
context.AddToParents(c);
context.SaveChanges(SaveChangesOptions.BatchWithSingleChangeset);
`
This does not work.
The text was updated successfully, but these errors were encountered: