doschi
doschi

Reputation: 134

Azure Mobile + Json.NET: Map class to table with different name

I'm using the Azure Mobile Service for a Windows Phone 8 project.

I am trying to store complex types in my database and therefore use json.net's JsonConverter.

My data-class looks like this:

public class Data
{
    ...
    [JsonConverter(typeof(MyConverter))]
    public ComplexType SomeMember{get;set;}
    ...    
}

That seems to work fine, but there is one problem: I want to map the 'Data'-class to a database table with a different name, like 'data_something'

This can be achieved by using

[DataContract(Name="data_something")]
public class Dat
{
    ...
}

But then the Json.NET Annotations are ignored.

Is there a way to use Json.NET and specify the Table-Name separately? Or perhaps another way to use Azure Mobile to get the right table even if the class name is not the same. (I'm currently using dataTable= MobileService.GetTable<Data>();)

Upvotes: 1

Views: 512

Answers (1)

carlosfigueira
carlosfigueira

Reputation: 87218

You can use the [DataTable] attribute for that:

[DataTable("data_something")]
public class Data
{
    [JsonConverter(typeof(MyConverter))]
    public ComplexType SomeMember { get; set; }
    // other members ommitted
}

Upvotes: 2

Related Questions