Migrate sqlite database from android studio app to Xamarin.Forms app

问题: I've been developing an android app for the last year or so in android studio. It has been in the play store since October and quite a few people are using it. I have rec...

问题:

I've been developing an android app for the last year or so in android studio. It has been in the play store since October and quite a few people are using it.

I have received many requests to create the same app for iOS and so after a lot of research I've settled on xamarin forms as it will be easier to code (as I'm familiar with c# and xaml) and less work to maintain the app for both platforms at the same time (even though it will take a while to port the code over).

The android app is using sqlite for data persistency and the xamarin version will do the same.

My question is, how could I port the sqlite databases of existing users to the new app once it is released? Is there a way to define the table/column names the same as I have set them in the android studio version?

Currently the app has a feature to export the database to the Downloads folder and the xamarin.forms app will import it from there.

I haven't seen anyone in any tutorial explicitly define the table and column names in their xamarin.forms sqlite implementation so I'm a bit worried to take the leap.

Is there a way to ensure that existing databases will work out of the box once imported in the xamarin.forms app? If not, could someone please point me towards a piece of code that will migrate data from one dB to another?

Thank you in advance for your time.

Regards


回答1:

As I got a bit more familiar with the SQlite package in Xamarin.Forms, turns out that the answer is as simple as adding the [Column("my_column")] attribute above the property in the model. This way it will name the column to whatever is specified in the brackets and I can make sure it matches the database schema I have in my current project from Android Studio.

a bit of a "duh!?" moment here for me but thank you to all who have taken the time to answer!

  • 发表于 2019-01-16 15:50
  • 阅读 ( 203 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除