我有一个包含3个表的应用程序
Items, Clients, Types
每个项目都可以与一个客户端和一个类型相关联
这最初是使用SQL Server CE存储的,现在我已将数据推送到azure移动服务。
我试图在用c#编写的新的Windows通用应用程序中重用这些数据。
在Azure中我创建了3个表项表表clienttable typetable,在itemtable中我有clienttable和typetable条目的id列(item.clienttableid = clienttable.id)。
Azure移动服务后端设置为javascript,我选择了这个,因为我认为它会比平台更兼容.net后端是真的吗?
我希望能够读取items表中的所有项目并引用客户端的属性并从项目中键入表格(例如item.client.clientname)
有没有办法定义我的类,这样当我从azure请求所有项目时,我也会获得相关的类型和客户端。
到目前为止,这就是我上课的方式
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; }
}
我见过这个http://blogs.msdn.com/b/carlosfigueira/archive/2013/08/23/complex-types-and-azure-mobile-services.aspx 但无法解决如何使其适应我的情况
答案 0 :(得分:1)
Azure移动服务后端设置为javascript,我选择了这个,因为我认为它会比平台更兼容.net后端是真的吗?
无论您使用的是哪个后端,在每种情况下都会很容易,因为Azure移动服务团队为客户端应用程序创建了一个“Azure Mobile Services SDK”,您可以通过“管理Nuget包”来安装它。 / p>
到目前为止,这就是我上课的方式
我看到了模型,下次您可以从模型中显示类图,请在本文Class diagram: a easy way to understand code中了解。如果这个模型是针对客户端/ .Net后端的,我认为这不完全正确,因为你说过这个
3表项目,客户和类型。每个项目可以与一个客户端和一个类型相关联
在ItemTable类中,你需要有类似的东西
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; }
注意:在客户端应用中删除属性ForeignKey。
如果您有疑问我建议您看看
Azure Mobile Services Samples - Samples and articles to help developers to use Azure Mobile Services