Azure 移动服务链接表



>我有一个有 3 个表的应用程序

Items, Clients, Types

每个项目可以关联到一个客户端和一个类型

这最初是使用 SQL Server CE 存储的,现在我已将数据推送到 Azure 移动服务。

我正在尝试在用 c# 编写的新 Windows 通用应用程序中重用此数据。

在 Azure 中,我创建了 3 个表 itemtable clienttable typetable,在 itemtable 中,我有 client 表和类型表条目 id 的列 (item.clienttableid = clienttable.id)。

Azure 移动服务后端设置为 javascript,我选择这个是因为我认为它比 .net 后端跨平台更兼容,是真的吗?

我希望能够从项目表中读取所有项目,并从项目中引用客户端和类型表的属性(例如 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但无法让我思考如何适应我的情况

Azure 移动服务后端设置为 javascript,我选择这个是因为我认为它比 .net 后端跨平台更兼容,是真的吗?

无论使用后端的哪个时间,每种情况下都很容易,因为 Azure 移动服务团队为客户端应用程序创建了一个"Azure 移动服务 SDK",你可以通过"管理 Nuget 包"进行安装。

这就是我到目前为止的班级方式

我看到了模型,下次你可以展示模型中的类图时,在这篇文章中了解类图:一种理解代码的简单方法。如果这个模型是针对客户端/.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; }

注意:在客户端应用中,删除属性外键。

如果你有疑问,我建议看看这个

Azure 移动服务

示例 - 帮助开发人员使用 Azure 移动服务的示例和文章

最新更新