Search code examples
entity-frameworkazureodataazure-mobile-services

TableController equivalent of EdmModel


I'm new this subject and trying to understand the differences between TableController, ApiController, and ODataController, so I can decide which one to use. I will be using OData and I think that all three of these controller base classes supply OData functionality. I will also be using Entity Framework Code First, so my default choice it seems would be TableController. But I'm considering that one of the alternatives may better fit my scenario.

Using ODataController starts with building an EdmModel. Although I looked at the library source code, I'm not seeing where TableController (together with EntityDomainManager) is building a static model like that. Perhaps it doesn't "build" a model but simply wraps that of the DbContext by performing operations on the entity's DbSet?

But what about an OData query that involves a navigation property? Does TableController/EntityDomainManager allow you to chain together a property path such as Order.Customer.Name in the query URL? Is the routing done using a predefined model or on the fly?


Solution

  • An ApiController is a WebAPI - no special functionality - just straight GET/POST/PUT/DELETE/etc. functionality that runs your code.

    An ODataController is an ApiController that implements the OData specification for data access.

    An Azure Mobile Apps TableController is an ApiController that implements the OData v3 specification with some extra bits to provide offline sync capabilities to a compatible client (specifically, the MobileServiceClient across iOS, Android, .NET (Xamarin/UWP/WP8.1) and Cordova) This takes the complexity out of defining the OData endpoint.

    There are semantic differences on how you define the endpoints, how to represent the query, etc.

    In terms of how it builds the model - it just wraps the DbContext - your Data Transfer Objects (DTOs) must inherit from EntityData - this gives the model the additional columns necessary to do offline sync (and note the Id column must be a string). Because a TableController is primarily a mobile capability, there are a bunch of caveats with their usage - relationships are particularly hard in an offline world, for instance. ODataController (which is online only) supports relationships - TableController requires work to support them.