EDIT-2: After several hours of research and almost every google-related google link that turned purple, I found out that the concept of "deep inserts" () exists in the OData specification. Therefore, in the end, what I am doing should work, even without links. Does anyone know how to enable this on a Microsoft OData client? Are there any other OData clients supporting this concept?
EDIT: Maybe this is the wrong approach, so please tell me if I am not doing this completely wrong. The inability to save really blocks our progress!
I have a problem with OData v3. I have an Associate class that has the required Address . When I try to POST the new helper, it fails because the Address property is null (EF6 throws a DbUpdateException with a foreign key violation). My Associate class is as follows:
public class Associate { public int Id { get; set; } [Required, StringLength(100)] public string Name { get; set; } [Required, StringLength(50)] public string Role { get; set; } public bool IsMailReceiver { get; set; } public bool IsLegalRepresentative { get; set; } [ForeignKey("AddressId")] public virtual Address Address { get; set; } public int AddressId { get; set; } }
I am using the Microsoft OData client and trying to add an associated element as follows:
var associate = new Associate { }; context.AddObject("Associates", associate); context.AddObject("Addresses", associate.Address); context.SetLink(associate, "Address", associate.Address); context.UpdateObject(associate); context.UpdateObject(associate.Address); context.SaveChanges();
On the server, in the controller, the assistant comes without a foreign key. When I test a POST request with Fiddler, I understand why:
{ "odata.type" : "xxx.Data.Entities.Associate", "AddressId" : 0, "Id" : 0, "IsLegalRepresentative" : false, "IsMailReceiver" : false, "Name" : "John Doe", "Role" : "Father" }
The address is not transmitted, although the generated class on the client has the Address property.
How can I solve this problem?