I am new in Azure , I am going to design a schema of One-To-Many relationship table.
For example :
User and Products , one user can own many products.
but I don't know how does Android Azure Client handle data to the backend(.Net)
in .Net , we use Entity Framework so we would design a class such like this :
class User{
...
public ICollection<Product> products {get;set;}
}
class Product{
...
public User user {get;set;}
}
to indicate intuitive One-To-Many relationship .
but how does Azure Android client handle the class and the properties to this?
Can I define in a same way on Entity Framework ??
otherwise , I will define like this :
class User{
int userId;
...
}
class Product{
...
int userId;
}
correspond to the schema defined in my database ... to indicate a One-To-Many Total relationship ....
sorry for my opaque description in English ...
Which way is more appropriate?
(and feel free to improve my description)
The format of data which transfer between client and backend is JSON. So you need to define the JSON structure first before defining the Data Transfer Object(DTO). The data transfer object on both client and backend sides will be serialized and deserialized based on the JSON structure.
For One-To-Many relationship, the following JSON structure would be fine.
{
"UserID": "U001",
"UserName": "John",
"products": [
{
"ID": "P001",
"Description": "Pencil"
},
{
"ID": "P002",
"Description": "Pen"
}
]
}
Corresponding C# DTO class model
public class User
{
public ICollection<Product> products { get; set; }
public string UserID { get; set; }
public string UserName { get; set; }
}
public class Product
{
public string ID { get; set; }
public string Description { get; set; }
}
Corresponding Java DTO class model
public class Product
{
@com.google.gson.annotations.SerializedName("ID")
private String id;
public String getID() { return this.id; }
public void setID(String value) { this.id = value; }
@com.google.gson.annotations.SerializedName("Description")
private String description;
public String getDescription() { return this.description; }
public void setDescription(String value) { this.description = value; }
}
public class User
{
@com.google.gson.annotations.SerializedName("UserID")
private String userID;
public String getUserID() { return this.userID; }
public void setUserID(String value) { this.userID = value; }
@com.google.gson.annotations.SerializedName("UserName")
private String userName;
public String getUserName() { return this.userName; }
public void setUserName(String value) { this.userName = value; }
@com.google.gson.annotations.SerializedName("products")
private List<Product> products;
public List<Product> getproducts() { return this.products; }
public void setproducts(List<Product> value) { this.products = value; }
}
For implementing the complex relationship using Azure Mobile Service SDK for Android, please refer to the last subsection How to: Store an object or array property into a table
at https://learn.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-android-how-to-use-client-library#a-namecustomizingahow-to-customize-the-client to use GSON library for client & refer to https://learn.microsoft.com/en-us/azure/app-service-mobile/app-service-mobile-node-backend-how-to-use-server-sdk#a-namecustomapia-custom-apis to implement the custon APIs for server.