[英]How can I load an already existing database into a UWP using entity framework or any other framework
I am trying to build a UWP app which loads an already existing database with entity framework. 我正在尝试构建一个UWP应用,该应用使用实体框架加载一个已经存在的数据库。 The only way i can create a database is if i create different database for each app installation but I want all my apps to share the same database. 创建数据库的唯一方法是,如果我为每个应用安装都创建了不同的数据库,但是我希望所有应用共享同一数据库。 Whenever i run 'Update-Database' in package manager, I get this error; 每当我在程序包管理器中运行“ Update-Database”时,都会出现此错误;
Update-Database should not be used with Universal Windows apps. Instead, call DbContext.Database.Migrate() at runtime.
Its little tricky but yes sir you can do that. 有点棘手,但是可以,先生,您可以这样做。
There is something called Publisher Cache Folder. 有一个叫做发布者缓存文件夹的东西。 This gives an option to create a shared folder that can be accessed by single publisher across multiple apps. 这提供了创建共享文件夹的选项,单个发布者可以在多个应用程序之间访问该共享文件夹。 So the trick here is first create a publisher cache folder from your app. 因此,这里的窍门是首先从您的应用创建发布者缓存文件夹。 Create a database in that folder and once done, you can access this folder from all your apps and have a single database for all your apps. 在该文件夹中创建一个数据库,完成后,您可以从所有应用程序访问该文件夹,并为所有应用程序使用一个数据库。
Good thing about this is if you have multiple apps that uses this folder, unless the last one is uninstalled, it will not be deleted. 这样做的好处是,如果您有多个使用此文件夹的应用程序,除非卸载了最后一个应用程序,否则不会将其删除。 So if your user uninstalls one of your app and installs it back again, voila, His old data that is stored in your database is already there. 因此,如果您的用户卸载了您的一个应用程序并再次安装回去,瞧,他存储在数据库中的旧数据已经在那里。
You can read the documentation here 您可以在这里阅读文档
Good Luck 祝好运
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.