3

We have created a Xamarin Forms application and currently just running on Android. Backend is .Net Azure Mobile Apps service

I understand from the articles that offline data sync only works with "/tables" endpoint. (at least thats what I understood)

But my API exposes data from joined queries (entity relationship), and some from stored procedures. Does it mean these can't apply to current SDK? What are my options?

Do I expose tables and handle the business logic for the joins in client end?

Anas Alweish
  • 2,818
  • 4
  • 30
  • 44
Randeep Singh
  • 998
  • 2
  • 11
  • 31

1 Answers1

5

You have a couple of options for relationships and offline sync.

1) Create a view with triggers. 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. 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.

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. 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. 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.

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/

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. There are trade offs with all of them.

Adrian Hall
  • 7,990
  • 1
  • 18
  • 26
  • I have read your articles. They are very useful. Is there an example showing the first way (Create a view with triggers). Thanks a lot. – Sapan Ghafuri Aug 11 '16 at 10:13