无法确定类型为“System.Data.Sqlite.SqliteFactory"的提供者工厂的提供者名称 [英] Unable to determine the provider name for provider factory of type "System.Data.Sqlite.SqliteFactory"

查看:26
本文介绍了无法确定类型为“System.Data.Sqlite.SqliteFactory"的提供者工厂的提供者名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的web api项目中使用sqlite实体框架,但总是不能很好地工作,

I want to use sqlite entity framework in my web api project, but it always can't work well,

这是我的开发环境.

1.Visual Studio 2013,.net 框架 4.5

1.Visual studio 2013, .net framework 4.5

  1. sqlite 包版本是 1.0.97,我安装了下面的包

  1. sqlite package version is 1.0.97, I installed below packages

system.data.sqlite,system.data.sqlite.ef6,system.data.sqlite.linq

system.data.sqlite, system.data.sqlite.ef6, system.data.sqlite.linq

EntityFramework 是 6.1.3

EntityFramework is 6.1.3

这是我得到的例外

无法确定System.Data.SQLite.SQLiteFactory"类型的提供者工厂的提供者名称.确保在应用程序配置中安装或注册了 ADO.NET 提供程序

这是我的网络配置

<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />  <!--type="System.Data.SQLite.EF6.SQLiteProviderServices-->
    </providers>
  </entityFramework>
  <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" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="Sqlite" connectionString="data source=&quot;D:MyWebAPIsrcMyWeb.ApiApp_Datasqlite_test.db&quot;" providerName="System.Data.SQLite.EF6" />
  </connectionStrings>
</configuration>

我可以通过visual studio工具中的连接数据库"连接sqlite数据库文件,也可以先用代码生成实体.

I can connect sqlite database file through "connect to database" in tool of visual studio, I also can generate entity using code first.

但是我无法正常获取数据

but I can't get data normal

这是我的代码

 public partial class Sqlite : DbContext
    {
        public Sqlite()
            : base("name=Sqlite")
        {
        }

        public virtual DbSet<AuthorizationLog> AuthorizationLogs { get; set; }
        public virtual DbSet<Checksum> Checksums { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<AuthorizationLog>()
                .Property(e => e.ClientKey)
                .IsUnicode(false);

            modelBuilder.Entity<AuthorizationLog>()
                .Property(e => e.Login)
                .IsUnicode(false);

            modelBuilder.Entity<AuthorizationLog>()
                .Property(e => e.Password)
                .IsUnicode(false);

            modelBuilder.Entity<AuthorizationLog>()
                .Property(e => e.ConnectionString)
                .IsUnicode(false);
        }
    }

   public class ValuesController : ApiController
    {
        // GET api/values
        Sqlite ctx = new WebApi2Demo.Sqlite();
        public IEnumerable<Checksum> Get()
        {
            return ctx.Checksums;
        }
	}

推荐答案

我自己得到了答案,但我仍然不知道根本原因,现在它可以工作了.我更改了 webconfig,这是使我的项目正常工作的 webconfig.

I got the answer by myself, but I still don't know the root cause, now it works. I changed webconfig, here is the webconfig that make my project to work.

我添加了一个System.Data.Sqlite"提供者,请注意其类型与 System.Data.Sqlite.EF6 相同

I added a provider that is "System.Data.Sqlite", Please note its type that is same with System.Data.Sqlite.EF6

  <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />

  <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
  <remove invariant="System.Data.SQLite.EF6" />

这里是所有配置.

 <entityFramework>
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
      <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
    </providers>
  </entityFramework>

  <system.data>
    <DbProviderFactories>
      <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" />
      <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" />
    </DbProviderFactories>
  </system.data>

这篇关于无法确定类型为“System.Data.Sqlite.SqliteFactory"的提供者工厂的提供者名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆