I'm struggling to find an example of how to create (POST) a new entity to an OData v4 service when there is a navigation property involved.
For example, let's say I have the following two models:
class Item
{
[Key]
public int Id { get; set; }
[Required]
public string Name { get; set; }
[Required]
public virtual Group Group { get; set;}
}
class Group
{
[Key]
public int Id { get; set; }
[Required]
public string Name { get; set; }
}
If I want to create an Item which should belong to an already-defined group (with, let's say, ID = 123), then I'll POST:
{
"Name": "New item",
"Group": ???
}
What do I need to specify for group? I'm assuming I need to refer to it by the ID somehow. Of course, I could include the foreign key in the Item entity (GroupId) and add that. That's how I'm doing it at the moment, and it works, but is this the only way to go? What should I be doing? Thanks.