【问题标题】:Azure Mobile Services linked tablesAzure 移动服务链接表
【发布时间】:2017-02-19 22:01:36
【问题描述】:

我有一个包含 3 个表的应用程序

Items, Clients, Types

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

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

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

在 Azure 中,我创建了 3 个表 itemtable clienttable typetable,在 itemtable 中,我有 clienttable 的 id 和 typetable 条目 (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 但无法理解如何适应我的情况

【问题讨论】:

    标签: c# azure win-universal-app azure-mobile-services


    【解决方案1】:

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

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

    这就是我目前上课的方式

    我看到了模型,下次您可以从模型中显示类图时,请在本文中了解 Class diagram: a easy way to understand code。如果这个模型是针对client/.Net Backend的,我觉得不完全正确,因为你这么说

    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

    【讨论】:

    • 感谢您的信息。我目前在 azure 移动服务的表中有数据,并将 itemclientid 和 itemtypeid 设置为与每个相应表中的 id 字段相同。我现在正在尝试使用这些数据并将其映射到适当的客户端或类型。我想我的问题真的是我是从 azure 中提取它作为视图,还是单独提取 3 个表并通过匹配 ID 在客户端上创建视图。我希望这是有道理的。
    猜你喜欢
    • 2016-11-25
    • 1970-01-01
    • 2013-01-29
    • 2016-12-17
    • 1970-01-01
    • 2016-07-07
    • 1970-01-01
    • 1970-01-01
    • 2016-09-04
    相关资源
    最近更新 更多