3

Ive come up against a major problem.

I am building a system which emloys a ASP.NET 4 Web App > Azure SQL > Azure Mobile Service > Windows Phone 8 app. The data is inputed into the Web Site which is already hosted on azure and which employs the Membership Provider and hence its default tables. This data is stored already successfully on Azure SQL db.

My major obstacle is Azure Mobile Services requires each and every table on it to have their primary key to be called "id" - lower case! Crazy in my opinion. And of course the Membership Provider has different names for PK's.

Question - Should I redesign my whole ASP.NET application (lot of time n effort) to use CUSTOM Membership (with PK coloum named "id") or try to find a way to try to change column name on the fly to "id" (no idea how to!). Has anyone any suggestions? Much appreciated in advance.

Shanyman
  • 41
  • 6

1 Answers1

1

I do not think that using Azure Mobile Services should push you to rework all of your existing architecture. That being said, thre are two possible solutions that you could try.

The first one is to actually not use the EntityData classes of Azure Mobile Service - it is not mandatory to inherit from EntityData in orer to use AMS. You need to inherit EntityData in case you want to use TableController which is probably a good idea since it provides you with a lot of builtin functionality but you can choose to use a plain ApiController and your current models.

Another possible solution is to use the so called DTOs (Data Transfer Objects) which can help you keep your current architecture but still be able to use AMS.

Here are some link with more info about DTO: What is Data Transfer Object? Create Data Transfer Objects (DTOs)

A possible implmentation:

Let's say that you have the following model:

public class MyUser
{
    public int MyId
    {
        get;
        set;
    }

    public string SomeOther
    {
        get;
        set;
    }
}

As you have pointed out, if you want to use this model with AMS you need to use their Id property instead of MyId. If you want to keep MyUser intact you can introduce the following class:

public class MyUserDTO : EntityData
{
    public string SomeOther
    {
        get;
        set;
    }
}

Now your service will use MyUserDTO which is like a proxy for your original model. The problem that you have to tackle is that you should convert between MyUserDTO and MyUser. If your models are simple and you do not have complex hierarchies that would be quite easy. If you have complex models DTOs might not be the correct approach. Automapper is a tool that can help you with mapping from model to DTOs and vice-versa.

Still, I do not have much information about your architecture and using DTOs might not be a good fit.

Community
  • 1
  • 1
Milan Nankov
  • 1,442
  • 12
  • 15