简体   繁体   English

具有视图或存储过程的Azure移动应用程序中的脱机数据同步

[英]Offline Data Sync in Azure Mobile Apps with Views or Stored Procedure

We have created a Xamarin Forms application and currently just running on Android. 我们已经创建了一个Xamarin Forms应用程序,目前只在Android上运行。 Backend is .Net Azure Mobile Apps service 后端是.Net Azure移动应用程序服务

I understand from the articles that offline data sync only works with "/tables" endpoint. 我从文章中了解到,离线数据同步仅适用于“/ tables”端点。 (at least thats what I understood) (至少那是我所理解的)

But my API exposes data from joined queries (entity relationship), and some from stored procedures. 但我的API公开了来自连接查询(实体关系)的数据,还有一些来自存储过程。 Does it mean these can't apply to current SDK? 这是否意味着这些不适用于当前的SDK? What are my options? 我有什么选择?

Do I expose tables and handle the business logic for the joins in client end? 我是否公开表并处理客户端中的连接的业务逻辑?

You have a couple of options for relationships and offline sync. 您有两种关系和离线同步选项。

1) Create a view with triggers. 1)使用触发器创建视图。 When an entry is inserted, updated or deleted - do "the right thing" for your backend tables. 插入,更新或删除条目时 - 为后端表执行“正确的操作”。 The view will automatically be updated. 视图将自动更新。 Your EF model should reference the view. 您的EF模型应该引用该视图。 This works completely offline since you are only dealing with one table (because it's actually a view). 这完全脱机,因为你只处理一个表(因为它实际上是一个视图)。 There is SQL complexity here and a lot of relationships can't be represented this way. 这里存在SQL复杂性,很多关系不能用这种方式表示。

2) Use individual tables as "read-only" - post/put/delete to a custom API to do the inserts, updates and deletes so that the referential integrity of your database is preserved. 2)将单个表用作“只读” - 发布/放置/删除到自定义API以执行插入,更新和删除操作,以便保留数据库的引用完整性。 This means your data is available offline but you can't update the database unless you are online 这意味着您的数据可以脱机使用,但除非您在线,否则无法更新数据库

3) Remove the relationships from your database and perform the joins, etc. on the client instead. 3)从数据库中删除关系,并在客户端上执行连接等。 This puts the onus on your client. 这将责任推卸给您的客户。 It also means your backend needs to enforce the integrity since you won't know that it's your client accessing the backend. 这也意味着您的后端需要强制执行完整性,因为您不知道它是您的客户端访问后端。 Probably not the best idea. 可能不是最好的主意。

4) Denormalize your data and restructure your database. 4)对数据进行非规范化并重构数据库。

I'm sure someone will come up with other ideas. 我相信有人会提出其他想法。 Check out my blog post on the subject as well: https://shellmonger.com/2016/05/27/30-days-of-zumo-v2-azure-mobile-apps-day-26-relationship-advice/ 查看我关于该主题的博文: https//shellmonger.com/2016/05/27/30-days-of-zumo-v2-azure-mobile-apps-day-26-relationship-advice/

Which one you choose depends on how much code you want to write, how comfortable you feel in T-SQL and what the actual data model looks like. 您选择哪一个取决于您想要编写多少代码,您对T-SQL的感觉以及实际数据模型的外观。 There are trade offs with all of them. 所有人都有权衡。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM