WebApi icon indicating copy to clipboard operation
WebApi copied to clipboard

Patch Delta is null

Open nidhimj22 opened this issue 9 years ago • 3 comments

HTTP Patch on entity does not work.

I have 2 entities. They have the following structure -

public class Entity1
 {
     public string Id { get; set; }
     public string Type { get; set; }
     public ICollection<Entity2> Entity2List { get; set; }
 }

 public class Entity2
 {
     public string Id { get; set; }
     public string Type { get; set; }
}

My Controller action is in the following format. It worked perfectly well before adding ICollection property in Entity1.

        [EnableQuery]
        [HttpPatch]
        [ODataRoute("({id})")]
        public IHttpActionResult PatchEntity1(string id, [FromBody][Required] Delta<Entity1> Entity1Delta)
        {
           // Entity1Delta here is null
         }

My Configuration file is as follows -

     internal static void Register(HttpConfiguration config)
    { 
        config.SetUrlKeyDelimiter(ODataUrlKeyDelimiter.Slash);
        config.Filter().Expand().Select().OrderBy().MaxTop(null).Count();

        config.MapODataServiceRoute(
             routeName: "ODataRoute",
             routePrefix: "api",
             model: GetModel());
    }
    /// <summary>
    /// Get the EDM for the ODataControllers
    /// </summary>
    private static IEdmModel GetModel()
    {
        ODataConventionModelBuilder builder = new ODataConventionModelBuilder();

        builder.EntitySet<Entity1>("entity1");
        builder.EntitySet<Entity2>("entity2");
       
        builder.EnableLowerCamelCase();
        return builder.GetEdmModel();
    }

nidhimj22 avatar Jun 08 '17 00:06 nidhimj22

Similar to: https://github.com/OData/WebApi/issues/945, #964

xuzhg avatar Jun 09 '17 23:06 xuzhg

I am having the same issue. Not able to tell if this issue has been addressed or not?

ricksearcy avatar Jan 03 '18 18:01 ricksearcy

@ricksearcy I was using it as a collection property and patch is not supported for that according to the spec. You can read the discussion here - https://github.com/OData/WebApi/issues/945 and https://github.com/OData/WebApi/blob/master/src/System.Web.OData/OData/Routing/Conventions/PropertyRoutingConvention.cs#L113

On using entity2 as a navigation property of entity1, Patch worked without any issues.

nidhimj22 avatar Jan 04 '18 04:01 nidhimj22