问题描述
这是使用 SQLite
数据库的 UWP
应用程序。下面是此应用程序的依赖项:
It is an UWP
application using a SQLite
database. Below, the dependencies for this application:
{
"dependencies": {
"Microsoft.EntityFrameworkCore.Sqlite": "1.0.1",
"Microsoft.EntityFrameworkCore.Tools": "1.0.0-preview2-final",
"Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2",
"Microsoft.Xaml.Behaviors.Uwp.Managed": "1.1.0",
"Newtonsoft.Json": "8.0.3",
"Template10": "1.1.*"
},
// ...
}
要求是: [...]具有从应用程序或任何其他可以打开 SQLite
数据库的应用程序访问数据库的密码。
The requirement is: "[...]to have a password to access the database either from the application or any other application that can open a SQLite
database".
实体框架核心似乎不支持这种情况。 有任何建议吗?
Entity Framework Core doesn't seem to support this scenario. Any suggestion?
推荐答案
请参阅我的帖子,以获取有关在Microsoft.Data.Sqlite中使用SQLCipher和朋友的提示。
See my Encryption in Microsoft.Data.Sqlite post for tips on using SQLCipher and friends with Microsoft.Data.Sqlite.
在EF Core中使用它的最简单方法可能是在您的 DbContext
中使用开放连接。
The easiest way to use it with EF Core is probably to use an open connection with your DbContext
.
class MyContext : DbContext
{
SqliteConnection _connection;
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
_connection = new SqliteConnection(_connectionString);
_connection.Open();
var command = _connection.CreateCommand();
command.CommandText = "PRAGMA key = 'password';";
command.ExecuteNonQuery();
options.UseSqlite(_connection);
}
protected override void Dispose()
{
_connection?.Dispose();
}
}
这篇关于保护UWP应用中的SQLite数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!