Sandbox Sqlite with EF Core

戏子无情 提交于 2021-02-11 12:29:20

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!