1

Closed

Provide action names with navigation property in LinkRoutingConvention

description

Instead of "CreateLink" or "DeleteLink" names for actions that this convention currently generates, could we have actions like "CreateLinkTo<NavigationProperty>" below out of the box?

Example: CreateLinkToFamily, CreateLinkToProducts

otherwise currently users would have to use conditional statement like below:

public HttpResponseMessage CreateLink(int key, string navigationProperty, [FromBody] Uri link)
    {
        Product product = _db.Products.SingleOrDefault(p => p.ID == key);

        int relatedKey = ODataHelper.GetKeyValue<int>(Request.GetConfiguration(), link);

        switch (navigationProperty)
        {
            case "Family":
                // The utility method uses routing (ODataRoutes.GetById should match) to get the value of {id} parameter 
                // which is the id of the ProductFamily.
                ProductFamily family = _db.ProductFamilies.SingleOrDefault(f => f.ID == relatedKey);
                product.Family = family;
                break;

            default:
                throw ODataErrors.CreatingLinkNotSupported(Request, navigationProperty);
        }
        _db.SaveChanges();

        return Request.CreateResponse(HttpStatusCode.NoContent);
    }
Closed Oct 11, 2013 at 3:45 PM by jacalvar

comments

HongmeiG wrote Dec 10, 2012 at 10:52 PM

Nice to have for RTM.