我一直在尝试使用Entity框架浏览sqlite db文件并读取数据。 但是以下方式不起作用 我用sqlite文件路径启动MydbContext 例如
using (var sourceContext = new MydbContext(@"D:\test\data.sqlite"))
{
var a= sourceContext.MyModel.ToList();
}
public MydbContext(string path)
: base(GetConnectionString(path))
{
Configuration.LazyLoadingEnabled = false;
}
public static string GetConnectionString(string path)
{
var entityConnectionString = new EntityConnectionStringBuilder
{
Metadata = "res://*",
Provider = "System.Data.SQLite.EF6",
ProviderConnectionString = sqlLiteConnectionString,
}.ConnectionString;
}
请使用sqlite和ef。建议是否有正确的方法来实现这一目标。
答案 0 :(得分:0)
得到了评论的答案
private static SQLiteConnection GetConnectionString(string path)
{
var con= new SQLiteConnection()
{
ConnectionString =
new SQLiteConnectionStringBuilder()
{ DataSource = path, ForeignKeys = true,BinaryGUID = false }
.ConnectionString
};
return con;
}