Using OData V3(#ref) or V4(#links) with in WebApi 2+ Controller and handling relationships:
Are Switch Statements the only way?
These 2 resources for each seem to indicate the necessity of a switch case for each navigation property.
- Entity Relations in OData V3
-
switch (navigationProperty) { case "Supplier": // Note: The code for GetKeyFromUri is shown later in this topic. var relatedKey = Helpers.GetKeyFromUri<int>(Request, link); var supplier = await db.Suppliers.SingleOrDefaultAsync(f => f.Id == relatedKey); if (supplier == null) { return NotFound(); } product.Supplier = supplier; break; default: return StatusCode(HttpStatusCode.NotImplemented); }
Question: Am I supposed to hard code a switch statement for each navigation property, and if so, is there a way to have this auto-magically scaffold?