Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# SQLite.CodeFirst“;提供程序未返回ProviderManifest实例。”;_C#_Sqlite_Entity Framework 6_Ef Code First_System.data.sqlite - Fatal编程技术网

C# SQLite.CodeFirst“;提供程序未返回ProviderManifest实例。”;

C# SQLite.CodeFirst“;提供程序未返回ProviderManifest实例。”;,c#,sqlite,entity-framework-6,ef-code-first,system.data.sqlite,C#,Sqlite,Entity Framework 6,Ef Code First,System.data.sqlite,我试图使用(1.5.1.25,从NuGet软件包安装)和(1.0.108,也是NuGet)使工作成为最简单的项目 但是,添加一个人将导致 提供程序未返回ProviderManifest实例 例外。 遗憾的是,没有官方的示例项目可以从中获得灵感,因此以下是几十个答案的汇总,因此我只能举一个简单的例子。 委员会: 班级人员 { [关键] 公共int ID{get;set;} 公共字符串名称{get;set;} } 类MyDBContentext:DbContext { 公共MyDBContentTe

我试图使用(1.5.1.25,从NuGet软件包安装)和(1.0.108,也是NuGet)使工作成为最简单的项目
但是,添加一个人将导致

提供程序未返回ProviderManifest实例

例外。 遗憾的是,没有官方的示例项目可以从中获得灵感,因此以下是几十个答案的汇总,因此我只能举一个简单的例子。
委员会:

班级人员
{
[关键]
公共int ID{get;set;}
公共字符串名称{get;set;}
}
类MyDBContentext:DbContext
{
公共MyDBContentText(字符串连接字符串)
:base(新SQLiteConnection(){ConnectionString=ConnectionString},true)
{ }
模型创建时受保护的覆盖无效(DbModelBuilder modelBuilder)
{
var sqliteConnectionInitializer=新的SqliteCreateDatabaseIfNotExists(modelBuilder);
System.Data.Entity.Database.SetInitializer(sqliteConnectionInitializer);
}
公共数据库集人物{get;set;}
}
//主要
var conStr=$“数据源=eftest.sqlite;版本=3;密码=123;”;
var ctx=新的MyDBContentext(conStr);

添加(newperson(){Name=“foo”})// 重新安装所有NuGet包(SQLite.CodeFirst、System.Data.SQLite和Entity framework)并清理解决方案解决了此问题。

对于将来出现此问题的用户,请从GAC中删除所有SQLite程序集。在我的情况下,我必须在具有管理员权限的命令提示符下运行以下命令:

gacutil –u System.Data.SQLite
gacutil –u System.Data.SQLite.Linq

SQLite.CodeFirst GitHub Repositroy包含一个示例,使用了所有支持的功能。
  <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>
gacutil –u System.Data.SQLite
gacutil –u System.Data.SQLite.Linq