0
votes

I have an application with 3 tables

Items, Clients, Types

Each item can be associated to one client and one type

This was originally stored using SQL Server CE and I have now pushed the data up to azure mobile services.

I am attempting to reuse this data in a new windows universal application written in c#.

In Azure I created 3 tables itemtable clienttable typetable, in itemtable I have columns for the id of the clienttable and typetable entry (item.clienttableid = clienttable.id).

The Azure mobile services backend is set to javascript, I chose this as I thought it would be more compatible across platforms than the .net backend is that true?

I want to be able to read all the items from the items table and reference the properties of the client and type table from the item (e.g. item.client.clientname)

Is there a way of defining my class so that when I request all items from azure I also get the associated type and client.

This is how I have my class so far

public class ItemTable
{
    public string Id { get; set; }

    [JsonProperty(PropertyName = "itemdate")]
    public DateTime ItemDate { get; set; }

    [JsonProperty(PropertyName = "itemamount")]
    public decimal ItemAmount { get; set; }

    [JsonProperty(PropertyName = "itemdescription")]
    public string ItemDescription { get; set; }

    [JsonProperty(PropertyName = "ItemClientID")]
    public ClientTable Client { get; set; }

    [JsonProperty(PropertyName = "ItemTypeID")]
    public TypeTable Type { get; set; }
}

public class ClientTable
{
    public string Id { get; set; }

    [JsonProperty(PropertyName = "clientname")]
    public string ClientName { get; set; }
}

public class TypeTable
{
    public string Id { get; set; }

    [JsonProperty(PropertyName = "typename")]
    public string TypeName { get; set; }
} 

I have seen this http://blogs.msdn.com/b/carlosfigueira/archive/2013/08/23/complex-types-and-azure-mobile-services.aspx but cannot wrap my head around how to adapt it to my situation

1

1 Answers

1
votes

The Azure mobile services backend is set to javascript, I chose this as I thought it would be more compatible across platforms than the .net backend is that true?

No matter which time of backend you are using, it will be easy in each case because Azure Mobile Services Team created a "Azure Mobile Services SDK" for client applications, which you can install by "Manage Nuget Package".

This is how I have my class so far

I saw the model and next time you can show the class diagram from your model, learn about in this article Class diagram: a easy way to understand code. If this model is for the client/.Net Backend, I think it is not completely correct because you said this

3 tables Items, Clients and Types. Each item can be associated to one client and one type

In the ItemTable class you need to have something like it

             public ClientTable ClientId { get; set; }
	
       [ForeignKey("ClientId")]
	   [JsonProperty(PropertyName = "ItemClientID")]
       public virtual ClientTable Client { get; set; }
  
	   public string TypeTableId { get; set; }

       [ForeignKey("TypeTableId")]
	   [JsonProperty(PropertyName = "ItemTypeID")]
       public virtual TypeTable TypeTable { get; set; }

Note: In client apps remove the attribute ForeignKey.

If you have doubts I recommend to see this

Azure Mobile Services Samples - Samples and articles to help developers to use Azure Mobile Services