简体   繁体   English

如何使用实体框架或任何其他框架将已经存在的数据库加载到UWP中

[英]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.

相关问题 当使用 wpf 中的实体框架在数据库中进行任何修改时,如何更新我的数据网格 - how can i update my datagrid when any modification done in database using entity framework in wpf 如何使用Entity Framework 6在运行时创建数据库和表? - How can I create a database and tables at runtime using Entity Framework 6? 如何使用Entity Framework 4.2执行数据库迁移? - How can I perform database migration using Entity Framework 4.2? 实体框架(现有数据库) - Entity Framework (existing database) 如何将现有实体附加到通用的实体框架上下文中? - How can I attach an existing entity to the entity framework context in generic? 如何使用实体框架检查数据库中是否已经存在数据 - How to check if data is already present in database using entity framework 具有SQLite和实体框架的UWP数据库 - UWP database with SQLite and Entity Framework 使用Entity Framework Code First开发,我能否在现有数据库中创建一个或多个表? - Using Entity Framework Code First Development, can I get it to create a table or tables in an existing database? 如何将基本表添加到使用Entity Framework创建TPH模型的现有实体? - How can I add a base table to an existing entity creating TPH model using Entity Framework? 如何基于具有实体框架的现有 DbContext 为 Docker 图像创建 SQL 服务器数据库方案? - How can I create the SQL Server database scheme for a Docker image based on an existing DbContext with Entity Framework?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM