Set up MySQL back-end in Azure for Xamarin Offline

2019-07-26 15:29发布

I have a MySQL database set up through the Azure Portal, currently hosted on ClearDB. I have created a mobile app using Xamarin Forms that implements an SQLite database which stores relevant information for my app in it. I am implementing offline sync functionality using the Microsoft.WindowsAzure.MobileServices.SQLiteStore library, and I am using functions such as:

  • await table.ToListAsync();

  • await table.UpdateAsync(entry);

  • await client.SyncContext.PushAsync();

  • await table.PullAsync("allEntry", table.CreateQuery());

The last thing I need to do is sync my local SQLite database with the Azure cloud MySQL database I have created. How do I implement this in C# (or Node.js .. or ANY language) such that my SQLite database can sync entries with my Azure MySQL database.

Thanks!

1条回答
成全新的幸福
2楼-- · 2019-07-26 15:49

According to your requirement, I tried to create my Azure Mobile App project via Visual Studio, and install MySql.Data.Entity 6.9.9 which supports MySQL for EF6, then create my table controller working with my DBContext for MySQL.

I created my db model that inherits the EntityData which contains the table column type DateTimeOffset, but I encountered a incompatible error message. Then I found there is a known bug in MySQL Connector as follows:

An Entity Framework DbContext object created with a column of type DateTimeOffset returned an error indicating that DateTimeOffset values were incompatible with DateTime and Timestamp values. (Bug #24732001)

I found a release note about MySQL Connector/NET, then I tried to upgrade to MySql.Data.Entity 7.0.7-m61, but another problem about TypeLoadException - MySqlEFConfiguration encountered.

Since your goal is to use offline sync for your Xamarin app with azure mobile app, I recommend that you could try to use sql database or azure table storage for your data storage instead of MySQL, which could build your mobile app backend in a simple way. You could refer to here for getting started with it.

查看更多
登录 后发表回答