EntityFramework-Reverse-POCO-Code-First-Generator icon indicating copy to clipboard operation
EntityFramework-Reverse-POCO-Code-First-Generator copied to clipboard

SQLite Support

Open Gravemind2401 opened this issue 6 years ago • 1 comments

I've created a fork of this project with support for SQLite databases when using the System.Data.SQLite NuGet package with EF6 which may be useful for mobile applications (namely UWP or Xamarin ones).

In its current state my fork will only work for SQLite since I'm not familiar enough with T4 to make the assembly and namespace imports optional, but the code is there if you'd like to include it.

Essentially it's just another SchemaReader class called SqliteSchemaReader that will be used instead if the DbConnection is a SQLite one (similar to the SqlCE check). Most of the code is the same as the SqlServer code, so some of it could potentially be pulled into the base class.

If you or anyone else would like to try it, below is the app config settings to use it with SQLite. Note the third provider - it is a copy of the second but with the invariantName changed. I'm not sure why, but if I don't include it I get a runtime error saying no provider found with the name 'System.Data.SQLite' (despite my connection string specifying to use the EF6 provider). Everything else should be added automatically when the SQLite NuGet package is installed.

  <connectionStrings>
    <add name="MyDbContext" connectionString="Data Source=path.to.database.db" providerName="System.Data.SQLite.EF6" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, 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.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>

Gravemind2401 avatar Oct 13 '18 11:10 Gravemind2401

Thanks @Gravemind2401

sjh37 avatar Nov 06 '18 22:11 sjh37

@sjh37 I saw SQLite support was added in 3.8.2 not long ago, thanks!

Gravemind2401 avatar May 28 '23 03:05 Gravemind2401