问题
I'm making a small web app which currently is using sqlite
+ EF Core 2.1
for storing data.
Are there any solutions that I can sandbox my sqlite database file ?
I mean to load my sqlite database with its data and triggers from my physical db file into memory.
Everytime when I turn on/off VS debugger, database will be refreshed with my existing data in physical file.
Thank you,
回答1:
Here's some code that literally does what you asked:
var sandboxConnection = new SqliteConnection("Data Source=:memory:");
sandboxConnection.Open();
using (var physicalConnection = new SqliteConnection("Filename=physical.db"))
{
physicalConnection.Open();
physicalConnection.BackupDatabase(sandboxConnection);
}
optionsBuilder.UseSqlite(sandboxConnection);
回答2:
Move the physical sqlite file outside of the web root in a secure folder. SqliteCipher can also be used to encrypt
来源:https://stackoverflow.com/questions/52846554/sandbox-sqlite-with-ef-core