Creating a Azure Mobile Service (also using OData) to create a generic BaseController for CURD operations.

Product that I am currently working on require Azure Mobile Service, as we have mobile app created with Xamarin using Azure Mobile Services to sync down the reference data. This is using .net 4.5

I am using exciting entities in the database, utilising exciting entities with Entity framework is quit easy, I just need to disable migrations in Mobile Service project – just to be safe.

This is my base entity is like

EntityData is part of Microsoft.WindowsAzure.Mobile.Service.

This will be my sample Question entity.

This is how my Glabal.asax.cs looks like

I am using WebApiConfig.Register() to register my dependancies using Autofac, later I will inject them to my controllers

My DbContext is like below

I will create the BaseController extending the TableController.

In the actual QuestionController will on ly have the constructor. below is the sample code

Using OData for querying
Now you can use mobile service on your Xamarin app as usual, But if you want to use the same controllers in a web app u can use the OData for your queries.

For more information on odata please click here

yeah its that simple, I think I love OData….

Leave a comment