【问题标题】:Azure Mobile Services and Universal Apps SQLite SynchronizationAzure 移动服务和通用应用 SQLite 同步
【发布时间】:2015-01-13 08:16:07
【问题描述】:

我有一个普通的通用应用程序,没什么花哨的,很简单。

有一个重量超过 200KB(甚至可能是 20MB,记住这一点)的 SQLite 数据库,我想在 Windows 8.1 和 Windows Phone 8.1 设备之间共享这个数据库。

我猜漫游数据还不够,对吗?

所以,我用谷歌搜索并找到了 Azure 移动服务,它真的很不错,但是提供的示例太简单了,我不知道如何扩展它。

我的数据库有 7 个表,其中一些是通过外键连接的。这是我的类的示例之一(数据库基于它)。

public class Meeting : INotifyPropertyChanged
{
        public Meeting() { }

        private int _id;
        [PrimaryKey, AutoIncrement]
        public int Id { get; set; }

        private int _adressId;
        public int AdressId { get; set; }

        private Adress _adress;
        [Ignore]
        public Adress Adress { get; set; }
}

那就是方法

private async Task InitLocalStoreAsync()
{
    if (!App.MobileService.SyncContext.IsInitialized)
    {
        var store = new MobileServiceSQLiteStore("MyDatabase.db");
        store.DefineTable<Adress>();
        store.DefineTable<Contractor>();
        store.DefineTable<Item>();
        store.DefineTable<ItemGroup>();
        store.DefineTable<Meeting>();
        store.DefineTable<Note>();
        store.DefineTable<Order>();

        await App.MobileService.SyncContext.InitializeAsync(store);
    }
}

我收到异常“从 'Projekt.DataModel.Meeting' 上的 'Adress' 获取值时出错。”

问题是:处理这个真的很难。没有更简单的解决方案吗?我现在什么都不需要,只需要同步我的数据库。请记住,我有一个通过外键连接的表。也许我跳过了一些有价值的示例或教程?

感谢您的所有帮助。

【问题讨论】:

    标签: sqlite azure-mobile-services win-universal-app


    【解决方案1】:

    你说得对,这个数据库对于漫游设置来说太大了。您应该能够让 Azure 移动服务适用于您的方案。

    管理关系的一种方法,尤其是在它们是一对多而不是多对多的情况下,是在后端创建连接表的数据库视图。然后,您只需与它们同步。请参阅我在此论坛主题上的消息,其中描述了它的工作原理:https://social.msdn.microsoft.com/Forums/azure/en-US/4c056373-d5cf-4ca6-9f00-f152d2b01372/best-practice-for-syncing-related-tables-in-offline-mode?forum=azuremobile

    您可能还对我们构建的解决方案加速器感兴趣,该加速器展示了您将如何在真实应用中连接所有内容:https://code.msdn.microsoft.com/windowsapps/Field-Engineer-501df99d

    如果您有更多问题,请随时在我们的产品团队定期监控的论坛中发帖:https://social.msdn.microsoft.com/Forums/azure/en-US/home?forum=azuremobile

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多