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

问题描述

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



这里是我的开发环境。

1.视频工作室2013,.net框架4.5


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



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


  2. EntityFramework是6.1.3


这是例外,我有



无法确定提供商工厂的提供商名称, System.Data.SQLite.SQLiteFactory。确保ADO.NET提供程序已在应用程序配置中安装或注册



这是我的webconfig



 < configuration> < configSections> < section name =entityFrameworktype =System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection,EntityFramework,Version = 6.0.0.0,Culture = neutral,PublicKeyToken = b77a5c561934e089requirePermission =false/> <! - 有关实体框架配置的更多信息,请访问http://go.microsoft.com/fwlink/?LinkID=237468  - > < / configSections> <&的EntityFramework GT; < defaultConnectionFactory type =System.Data.Entity.Infrastructure.LocalDbConnectionFactory,EntityFramework> <参数> < parameter value =mssqllocaldb/> < /参数> < / defaultConnectionFactory> <&提供商GT; < provider invariantName =System.Data.SQLite.EF6type =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数据提供程序(实体框架6)invariant =System.Data.SQLite.EF6description =.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 =SqliteconnectionString = data source =&D:\MyWebAPI\src\MyWeb.Api\App_Data\sqlite_test.db& quot;providerName =System.Data.SQLite.EF6/>< / connectionStrings>< / configuration>  



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



但我无法获取数据正常



以下是我的代码



  public partial class Sqlite:DbContext {public Sqlite():base(name = Sqlite){} public virtual DbSet< AuthorizationLog> AuthorizationLogs {get;组; } public virtual DbSet< Checksum>校验和{get;组; } 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<校验和> Get(){return ctx.Checksums; }}  

解决方案得到自己的答案,但我仍然不知道根本原因,现在它的工作。我改变了webconfig,这里是webconfig让我的项目工作。



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

 < provider invariantName =System.Data.SQLitetype =System Data.SQLite.EF6.SQLiteProviderServices,System.Data.SQLite.EF6/> 
 < add name =SQLite Data Providerinvariant =System.Data.SQLitedescription =.NET Framework Data Provider for SQLitetype =System.Data.SQLite.SQLiteFactory,System.Data.SQLite /> 
< remove invariant =System.Data.SQLite.EF6/>

这里是全部配置。

 < entityFramework> 
< providers>
< provider invariantName =System.Data.SqlClienttype =System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer/>
< provider invariantName =System.Data.SQLite.EF6type =System.Data.SQLite.EF6.SQLiteProviderServices,System.Data.SQLite.EF6/>
< provider invariantName =System.Data.SQLitetype =System.Data.SQLite.EF6.SQLiteProviderServices,System.Data.SQLite.EF6/>
< / providers>
< / entityFramework>

< system.data>
< DbProviderFactories>
< remove invariant =System.Data.SQLite/>
< add name =SQLite数据提供者invariant =System.Data.SQLitedescription =.NET Framework Data Provider for SQLitetype =System.Data.SQLite.SQLiteFactory,System.Data.SQLite />
< remove invariant =System.Data.SQLite.EF6/>
< add name =SQLite数据提供程序(实体框架6)invariant =System.Data.SQLite.EF6description =.NET Framework Data Provider for SQLite(Entity Framework 6)type =System .Data.SQLite.EF6.SQLiteProviderFactory,System.Data.SQLite.EF6/>
< / DbProviderFactories>
< /system.data>


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

here is my development enviroment.

1.Visual studio 2013, .net framework 4.5

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

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

  2. EntityFramework is 6.1.3

Here is exception that I got

Unable to determine the provider name for provider factory of type 'System.Data.SQLite.SQLiteFactory'. Make sure that the ADO.NET provider is installed or registered in the application config

Here is my webconfig

<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:\MyWebAPI\src\MyWeb.Api\App_Data\sqlite_test.db&quot;" providerName="System.Data.SQLite.EF6" />
  </connectionStrings>
</configuration>

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

Here is my code

 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;
        }
	}

解决方案

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.

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" />

Here is all configure.

 <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”类型的供应商工厂的提供商名称。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 23:52