Base does not exist, I do through Code First. It is necessary that the database and all tables are created automatically according to the classes of the models.

I connect System.Data.SQLite.EF6 through NuGet, I register connection configs, I create models, a context, further errors.

Configs (were created automatically, registered only connectionStrings):

<?xml version="1.0" encoding="utf-8"?> <configuration> <configSections> <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /> </configSections> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" /> </startup> <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.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="DbConnection" connectionString="Data Source=C:\test.db;Version=3" providerName="System.Data.SQLite.EF6" /> </connectionStrings> </configuration> 

Context:

 public class ProjectContext : DbContext { public ProjectContext() : base("DbConnection") { } public DbSet<Account> Accounts { get; set; } } 

As a result, throws an exception on the line public ProjectContext (): base ("DbConnection")

Unhandled exception of type "System.InvalidOperationException" in mscorlib.dll

More information: The Entity Framework provider type 'System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6' registered with the application system 'System.Data.SQLite.EF6 'could not be loaded. Make sure that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

Tell me, please, where is it?

UPD: Added System.Data.SQLite with NuGet'a, the context is created normally. However, it now throws an exception when trying to add a model object to the DbSet context:

No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SQLite'.

  • EF6 can not create a database SQLite, have to create hands. - ixSci
  • @ixSci, read about it, thought corrected. Tell me, can tables be created / modified? Does migrations work? - tretetex
  • 2
    I did not go deep, but as far as I understand that it is precisely because of the inability to work with migrations that this plugin does not try to create a base. But EF Core already supports SQLite, so if you can, look in this direction. - ixSci

1 answer 1

It is necessary to tighten the libraries for EF work with SQLite , specifically System.Data.SQLite .

Personally, I did it a little bit, not in hipsters, but it works.

 private static SQLiteConnection CreateConnection(string path) { var builder = (SQLiteConnectionStringBuilder)SQLiteProviderFactory.Instance.CreateConnectionStringBuilder(); if (builder == null) return null; builder.DataSource = path; builder.FailIfMissing = false; return new SQLiteConnection(builder.ToString()); } /// <summary> /// Контекст для создания БД /// </summary> private sealed class AppDbContext : DbContext { public AppDbContext() : base(CreateConnection(DataBaseConnectionString), false) { } public DbSet<Account> Accounts { get; set; } public DbSet<Group> Groups { get; set; } public DbSet<TaskBase> Tasks { get; set; } protected override void OnModelCreating(DbModelBuilder modelBuilder) { if (!File.Exists(DataBaseConnectionString)) { var initializer = new SQLite.CodeFirst.SqliteDropCreateDatabaseAlways<AppDbContext>(modelBuilder); Database.SetInitializer(initializer); base.OnModelCreating(modelBuilder); } } 

In App.config (or Web.config for ASP )

 <?xml version="1.0" encoding="utf-8"?> <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> <startup> <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> </startup> <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" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" /> <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.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></configuration> 
  • I used to work with MS SQL, I transferred DbConnection , it worked fine, it remained from there. I’m trying to connect to SQLite for the first time, I don’t know the details yet, obviously I’m not doing it right. When connecting to SQLite, the connection name does not need to be transferred? Completed the question, please see. Now swears at connection, probably just because of a name. - tretetex
  • Ok, copied from your project. - Sergey
  • Thanks, helped! I also had to pull up SQLite.CodeFirst from nuget. - tretetex