简体   繁体   中英

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. 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 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM