【问题标题】:Azure Mobile Apps specific properties of entity in TableControllerTableController 中实体的 Azure 移动应用特定属性
【发布时间】:2017-08-08 11:24:19
【问题描述】:

借助 Azure 移动应用,我们可以在表之间进行同步。我正在构建具有不同目的的多个应用程序。其他应用程序不需要特定表的所有属性,只需要他需要的一次。是否可以仅将表的特定属性从 Web API 返回给客户端?如果这是可能的,当我只将属性推送到客户端正在使用的 Web API 时。这会仅影响那些属性的表数据吗?

我已经在类似的网站上搜索过,但找不到这个: https://shellmonger.com/30-days-of-azure-mobile-apps-the-table-of-contents/ https://adrianhall.github.io/develop-mobile-apps-with-csharp-and-azure/

【问题讨论】:

  • 你有关于这个线程的任何更新吗?如果有帮助,请将其标记为答案,以帮助更多有相同问题的社区。​​span>

标签: c# azure mobile


【解决方案1】:

是否可以只将表格的特定属性从 Web API 返回给客户端?

是的,Azure 移动应用 SDK 支持相当多的 OData v3 规范,我们可以通过使用 $select 子句来选择特定字段。更多详情请参考Data Access Concepts

当我只将属性推送到客户端正在使用的 Web API 时。这会仅影响那些属性的表数据吗?

我们可以做到。在我看来,如果我们想更新所有属性的一部分,那么我们可能需要包括id fieldversion fieldId 字段文件使表实体全局唯一。Version 字段是关于冲突检测的。

如果有任何冲突,我们可以使用我们的逻辑来处理冲突。更多详细信息请参考Handling Conflict Resolution。以下是文档中的演示代码。

sync Task ResolveConflictAsync(MobileServiceTableOperationError error)
{
    var serverItem = error.Result.ToObject<T>();
    var localItem = error.Item.ToObject<T>();

    // Note that you need to implement the public override Equals(TodoItem item)
    // method in the Model for this to work
    if (serverItem.Equals(localItem))
    {
        // Items are the same, so ignore the conflict
        await error.CancelAndDiscardItemAsync();
        return;
    }

    // Client Always Wins
    localItem.Version = serverItem.Version;
    await error.UpdateOperationAsync(JObject.FromObject(localItem));

    // Server Always Wins
    // await error.CancelAndDiscardItemAsync();
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-15
    相关资源
    最近更新 更多