Xamarin Forms,Sqlite,EF Core 3,迁移和大量混淆 [英] Xamarin Forms, Sqlite, EF Core 3, migrations, and lot of confussion

查看:84
本文介绍了Xamarin Forms,Sqlite,EF Core 3,迁移和大量混淆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Xamarin Forms应用程序,我已从仅使用Restful API切换为使用本地SQLite DB,它将使用此 Dotmim.Sync-数据库同步框架(太好了!).我在Xamarin表单项目中使用EF Core 3与SQLite进行交互.

I have a Xamarin Forms app that I have switched from using only restful API to using local SQLite DB, that will sync using this Dotmim.Sync - DB Sync'ing Framework (which is great!). I am using EF Core 3 in the Xamarin forms project to interact with SQLite.

我的问题是有关在SQLite上运行迁移或只是数据库更新.我已经阅读了一些有关不同方法的博客和论坛,但是从EF Core 1到EF Core 2,它们都有很多年的历史了,并且有很多工作要做.

My questions are around running migrations or just database updates on SQLite. I have read several blogs and forums about different approaches, but they all are several years old, from EF Core 1 to EF Core 2, and lots of work around.

  1. https://forums.xamarin.com/discussion/101805/xamarin-android-entity-framework-core-2-and-migrations -讨论通过添加控制台应用程序运行迁移
  2. https://medium.com/@yostane/entity-framework-core-and-sqlite-database-migration-using-vs2017-macos-28812c64e7ef -这是 Dot Net Cli工具参考.我尝试了这个并遇到错误,但它也出现了EF Core 1.1
  3. https://www.algoworks.com/Blog/xamarin-forms-and-entity-framework-core/-给了我更多的问题,然后是答案.
  1. https://forums.xamarin.com/discussion/101805/xamarin-android-entity-framework-core-2-and-migrations - this talks about running migrations by add console application
  2. https://medium.com/@yostane/entity-framework-core-and-sqlite-database-migration-using-vs2017-macos-28812c64e7ef - this add's a Dot Net Cli Tool Reference. I tried this and got errors, but it also EF Core 1.1
  3. https://www.algoworks.com/blog/xamarin-forms-and-entity-framework-core/ - gave me more questions then answers.

还有更多链接,但是我,这些证明了我采用的所有不同方法的观点.

There are more links but I, these prove my point of all the different approaches taken.

我想要实现的是:

  1. 当用户打开应用程序时,它会检查是否有数据库版本更新或应用程序已更新,并且知道它必须更新数据库.
  2. 有数据库更新时,Dotmim.Sync框架将控制配置和取消配置客户端上的数据库(Xamarin表单).这使您有机会运行EFCore迁移或SQL脚本来更新SQLite存储.
  1. When a user opens the app, it checks if there is DB version update, or the app updated and knows it has to update the database.
  2. When there is a DB update, Dotmim.Sync Framework is in control of Provisioning and Deprovisioning the database on the client (Xamarin Forms). Which gives the opportunity to run EFCore Migrations or SQL Sricpts to update the SQLite store.

选项1 我想走EF核心迁移之路,因为主数据库已通过迁移进行更新,所以该应用程序将能够利用相同的脚本.如果可以在运行时在Xamarin表单上运行迁移,那就太好了.

Option 1 I would like to go the EF Core Migration path, since the Master DB is updated with Migrations, The App would be able to leverage the same scripts. If running migrations on Xamarin forms at runtime is possible that would be great.

第一季度.EF Core是否可以与.netcore/netframework项目中的运行时一样在Xamarin Forms应用程序中运行迁移?

Q1. Can EF Core run mirgations in Xamarin Forms apps during runtime, same as it would in .netcore/netframework project?

选项2 如果正在运行的脚本需要很好的路径,我已经探讨过,这意味着我需要能够对SQLite模式进行比较工具1 工具2 ,我在SQLite db3上尝试了一种工具,但它出错了.除非经过验证,否则不愿意为工具2付费.

Option 2 If running scripts needs to be the path thats fine, which i have explored and means I need to be able to SQLite schema compares Tool 1 and tool 2, I tried the tool one on SQLite db3 and it error'ed. Wasn't willing to pay for Tool 2 unless without verification it works.

第二季度.是否有一个SQLite比较工具来生成架构更改?

Q2. Is there a SQLite compare tool to generate schema changes?

第三季度.还是部署在客户端上的sqlite的数据库更新路径是什么,那会更好,即删除数据库并重新创建它?然后重新同步数据库,以加载回所有用户特定的数据.数据丢失的可能性将很小,应用程序中的同步逻辑将很频繁,不确定每次用户数据更改事件之后是否发生,但是如果我们需要确保服务器永不同步,则可能会发生.

Q3. Or what is database update path for sqlite deployed on clients, that would be better, i.e drop the DB and just recreate it? then re sync the DB, to load back all user specific data. The chances of lost data would be minimal, the sync logic in the App will be frequent, not sure after every user data change event, but possible if we need to make sure the server never out of sync.

我希望我说清楚了.谢谢

I hope I made this clear. Thanks

推荐答案

您将需要创建安装说明工具.之后,正常的迁移工作流程应该可以在Xamarin上使用(请确保 让我们知道.

You'll need to create the dummy console app as mentioned. Here are instruction for installing the tools. After that, the normal Migrations workflow should work on Xamarin (Be sure to let us know if it doesn't).

Add-Migration MyMigration -P MyNetStandardClassLibrary -S DummyNetCoreApp

您可以使用以下方法在运行时应用迁移:

You can apply migrations at runtime using this method:

myDbContext.Database.Migrate();

这篇关于Xamarin Forms,Sqlite,EF Core 3,迁移和大量混淆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆