c# - Unable to determine the provider name for provider factory of type "System.Data.Sqlite.SqliteFactory" -


i want use sqlite entity framework in web api project, can't work well,

here development enviroment.

1.visual studio 2013, .net framework 4.5

  1. sqlite package version 1.0.97, installed below packages

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

  2. entityframework 6.1.3

here exception got

unable determine provider name provider factory of type 'system.data.sqlite.sqlitefactory'. make sure ado.net provider installed or registered in application config

here 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" />      <!-- 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 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 database" in tool of visual studio, can generate entity using code first.

but can't data normal

here 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      {          // api/values          sqlite ctx = new webapi2demo.sqlite();          public ienumerable<checksum> get()          {              return ctx.checksums;          }  	}

i got answer myself, still don't know root cause, works. changed webconfig, here webconfig make project work.

i added provider "system.data.sqlite", please note type same 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 sqlite" type="system.data.sqlite.sqlitefactory, system.data.sqlite" />   <remove invariant="system.data.sqlite.ef6" /> 

here 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 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 sqlite (entity framework 6)" type="system.data.sqlite.ef6.sqliteproviderfactory, system.data.sqlite.ef6" />     </dbproviderfactories>   </system.data> 

Comments

Popular posts from this blog

c - Bitwise operation with (signed) enum value -

xslt - Unnest parent nodes by child node -

YouTubePlayerFragment cannot be cast to android.support.v4.app.Fragment -