Sqlite not work with Entity Framework 6 -
i have small project sqlite , entity framework 6.
i install sqlite package manager console: pm>install-package system.data.sqlite
in web.config:
<connectionstrings> <remove name="demosqliteonnectionstring" /> <add name="demosqliteonnectionstring" connectionstring="data source=|app_data|demodata.s3db" providername="system.data.sqlite.ef6" /> </connectionstrings> <entityframework> <defaultconnectionfactory type="system.data.entity.infrastructure.localdbconnectionfactory, entityframework"> <parameters> <parameter value="v11.0" /> </parameters> </defaultconnectionfactory> <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" /> </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> in context class:
public class datacontext : dbcontext { public datacontext() : base("demosqliteonnectionstring") { database.setinitializer(new createdatabaseifnotexists<datacontext>()); } public dbset<client> client { get; set; } protected override void onmodelcreating(dbmodelbuilder modelbuilder) { // chinook database not pluralize table names modelbuilder.conventions .remove<pluralizingtablenameconvention>(); } } when instance of context: var context = new datacontext(),
it shows error:
additional information: no entity framework provider found ado.net provider invariant name 'system.data.sqlite'. make sure provider registered in 'entityframework' section of application config file. see http://go.microsoft.com/fwlink/?linkid=260882 more information.
how fix problem?
you should change app config file
<providers> <provider invariantname="**system.data.sqlite.ef6**" type="system.data.sqlite.ef6.sqliteproviderservices, system.data.sqlite.ef6" /> </providers> </providers> to
<providers> <provider invariantname="**system.data.sqlite**" type="system.data.sqlite.ef6.sqliteproviderservices, system.data.sqlite.ef6" /> </providers> </providers> and change configuration file :
public class datacontext : dbcontext { public datacontext() : base("demosqliteonnectionstring") { } public dbset<client> client { get; set; } protected override void onmodelcreating(dbmodelbuilder modelbuilder) { // chinook database not pluralize table names modelbuilder.conventions .remove<pluralizingtablenameconvention>(); database.setinitializer(new sqlitecreatedatabaseifnotexists<datacontext>(modelbuilder)); } }
Comments
Post a Comment