我有一个普通的通用应用程序,没有什么花哨,非常简单 .
有一个SQLite数据库,重量超过200KB(甚至可以是20MB,记住这一点),我想在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'获取 Value 时出错 . ”
The thing is: It is really hard to work with this. Isn't there a simplier solution? I don't need at this moment nothing but synchronization of my database. Please remember that I have a tables that are connected by foreign key. Maybe I skip some worthy example or tutorial?
感谢你的帮助 .
1 回答
你是对的,这个数据库对于漫游设置来说太大了 . 您应该能够使Azure移动服务适用于您的方案 .
管理关系的一种方法是在后端创建连接表的数据库视图,特别是如果它们是1对多关系而不是多对多关系 . 然后你只需同步他们 . 请参阅此论坛帖子中的消息,该消息描述了这将如何工作: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