SQLite.CodeFirst "The provider did not return a ProviderManifest instance."
SQLite.CodeFirst "The provider did not return a ProviderManifest instance."
我正在尝试使用 SQLite.CodeFirst (1.5.1.25, installed from NuGet package) along with the System.Data.SQLite(1.0.108,还有 NuGet)使工作成为最简单的项目。
但是,添加一个人会导致
The provider did not return a ProviderManifest instance.
异常。
可悲的是,没有官方示例项目可以从中汲取灵感,因此以下是数十个 SO 答案的汇总让我遵循了最小的示例。
context:
class Person
{
[Key]
public int ID { get; set; }
public string Name { get; set; }
}
class MyDBContentext : DbContext
{
public MyDBContentext(string connectionString)
: base(new SQLiteConnection() { ConnectionString = connectionString }, true)
{ }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
var sqliteConnectionInitializer = new SqliteCreateDatabaseIfNotExists<MyDBContentext>(modelBuilder);
System.Data.Entity.Database.SetInitializer(sqliteConnectionInitializer);
}
public DbSet<Person> People { get; set; }
}
//main
var conStr = $"Data Source=eftest.sqlite;Version=3;Password=123;";
var ctx = new MyDBContentext(conStr);
ctx.People.Add(new Person() { Name = "foo" });//<--- exception throw here
var res = ctx.SaveChanges();
和 App.config:
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite.EF6" />
<add name="SQLite Data Provider (Entity Framework 6)"
invariant="System.Data.SQLite.EF6"
description=".NET Framework Data Provider for SQLite (Entity Framework 6)"
type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite"
description=".Net Framework Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
<entityFramework>
<providers>
<provider invariantName="System.Data.SQLite.EF6"
type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SQLite"
type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
还有一个内部异常(翻译,因为它忽略线程文化)如果有任何相关性:
The attempt of method
System.Data.SQLite.EF6.SQLiteProviderManifest.GetProviderManifestToken(System.String)
to access the method
System.Data.SQLite.UnsafeNativeMethods.GetSettingValue(System.String,
System.String) failed.
重新安装所有 NuGet 包(SQLite.CodeFirst、System.Data.SQLite 和 Entity framework)并清理解决方案解决了问题。
对于将来遇到此问题的用户,请从您的 GAC 中删除所有 SQLite 程序集。就我而言,我必须 运行 从具有管理员权限的命令提示符执行以下操作:
gacutil –u System.Data.SQLite
gacutil –u System.Data.SQLite.Linq
我正在尝试使用 SQLite.CodeFirst (1.5.1.25, installed from NuGet package) along with the System.Data.SQLite(1.0.108,还有 NuGet)使工作成为最简单的项目。
但是,添加一个人会导致
The provider did not return a ProviderManifest instance.
异常。
可悲的是,没有官方示例项目可以从中汲取灵感,因此以下是数十个 SO 答案的汇总让我遵循了最小的示例。
context:
class Person
{
[Key]
public int ID { get; set; }
public string Name { get; set; }
}
class MyDBContentext : DbContext
{
public MyDBContentext(string connectionString)
: base(new SQLiteConnection() { ConnectionString = connectionString }, true)
{ }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
var sqliteConnectionInitializer = new SqliteCreateDatabaseIfNotExists<MyDBContentext>(modelBuilder);
System.Data.Entity.Database.SetInitializer(sqliteConnectionInitializer);
}
public DbSet<Person> People { get; set; }
}
//main
var conStr = $"Data Source=eftest.sqlite;Version=3;Password=123;";
var ctx = new MyDBContentext(conStr);
ctx.People.Add(new Person() { Name = "foo" });//<--- exception throw here
var res = ctx.SaveChanges();
和 App.config:
<system.data>
<DbProviderFactories>
<remove invariant="System.Data.SQLite.EF6" />
<add name="SQLite Data Provider (Entity Framework 6)"
invariant="System.Data.SQLite.EF6"
description=".NET Framework Data Provider for SQLite (Entity Framework 6)"
type="System.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6" />
<remove invariant="System.Data.SQLite" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite"
description=".Net Framework Data Provider for SQLite"
type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
<entityFramework>
<providers>
<provider invariantName="System.Data.SQLite.EF6"
type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
<provider invariantName="System.Data.SqlClient"
type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="System.Data.SQLite"
type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
</providers>
</entityFramework>
还有一个内部异常(翻译,因为它忽略线程文化)如果有任何相关性:
The attempt of method System.Data.SQLite.EF6.SQLiteProviderManifest.GetProviderManifestToken(System.String) to access the method System.Data.SQLite.UnsafeNativeMethods.GetSettingValue(System.String, System.String) failed.
重新安装所有 NuGet 包(SQLite.CodeFirst、System.Data.SQLite 和 Entity framework)并清理解决方案解决了问题。
对于将来遇到此问题的用户,请从您的 GAC 中删除所有 SQLite 程序集。就我而言,我必须 运行 从具有管理员权限的命令提示符执行以下操作:
gacutil –u System.Data.SQLite
gacutil –u System.Data.SQLite.Linq