發表文章

目前顯示的是 12月 20, 2018的文章

C# OData GetKeyFromUri - Resource not found for the segment 'odata'

圖片
0 I've updated from Microsoft.AspNet.OData version 6.0.0 to OData version 7.0.1. The upgrade has broken my ability to get the Id from a path when linking one object to another. Here is my Web API call to add a role to a specific user using the OData standard: POST: http://localhost:61506/odata/users('bob')/roles/$ref Request body: {"@odata.id":"http://localhost:61506/odata/roles(1)"} The Web API method verifies the user and then makes a call to Helpers.GetKeyFromUri to get the role Id value from the request body. [HttpPost, HttpPut] public IHttpActionResult CreateRef([FromODataUri] string key, string navigationProperty, [FromBody] Uri link) { // Ensure the User exists User user = new User().GetById(key); if (user == null) { return NotFound(); }