none
OData - Insert an entity with a relationship

    Question

  • Hello,

    I realized an OData service - EntityFramework that works well (V4).

    I just have a problem when I want to insert an entity with a relationship to an existing entity (relationship n-n).
    I tried using @data.bind for that :

    URL : https://.../myService/myEntityAs
    JSON :
    {
     "Attribut1" : "value1",
     "Attribut2" : "value2",
        ...
     "MyEntityB@odata.bind" : ["/MyEntityBs(123)"]
    }

    I do not have an error during POST, but only the entity A is add, but not the relation.

    My question is the following :
    - Does the use of @data.bind require a service-side implementation or is it out of the box?
    - If yes what is the approach ?

    Thank you in advance

    Thursday, March 14, 2019 12:25 PM

All replies

  • Hi,

    Here is a document about OData and Entity Framework maybe you can refer to:

    Entity Relations in OData v4 Using ASP.NET Web API 2.2.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, March 15, 2019 9:55 AM
  • Thank you for your reply.

    This article only talks about the option @odata.id and not about @odata.bind

    And in addition the code given as an example does not compile with the latest version "Microsoft.AspNet.OData" version="7.1.0"
    Especially with ProductService.Helpers.GetKeyFromUri

    Is it possible to have an example, such as the implementation in Dynamic ?

    Regards

    Friday, March 15, 2019 4:39 PM
  • Hi,

    As to "Dynamic", I found a document maybe you can follow:

    Create an entity using the Web API.

    Regards,

    Kyle


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, March 18, 2019 9:58 AM
  • Hi,

    Indeed it is exactly the subject that interests me.
    But this article is about consumer consumption or what interests me is the backend implementation.

    Regards

    Friday, March 22, 2019 1:59 PM