msallin/SQLiteCodeFirst

.Net 4 does not work.

HarelM opened this issue · 5 comments

First of all great project, This is very much needed to SQLite-EF users!
As mentioned in other issues when downgrading to .Net 4 the code breaks due to App.config changes.
However, using the same App.config from here will not work either.
After a few trials and errors I have managed to make it work.
Below is the final app.config that worked for me.
Can you add steps to overcome this issue in the Readme.md file so that other may use it as well.
(I think the only difference is in the connections string)

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <connectionStrings>
    <add name="footballDb" connectionString="data source=.\footballDb.sqlite" providerName="System.Data.SQLite.EF6" />
  </connectionStrings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
  </startup>
  <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>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </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" />
      <provider invariantName="System.Data.SQLite" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />
    </providers>
  </entityFramework>
</configuration>

Thanks,
Harel M.

Hello Harel

Thank you for your contribution!
I just tried it by myself. Here is what I did:

  1. Change the Project "SQLite.CodeFirst" to .NET 4.0
  2. In Package Manager Console "Update-Package –reinstall System.Data.SQLite"
  3. Change the Project "SQLite.CodeFirst.Console" to .NET 4.0
  4. In Package Manager Console "Update-Package –reinstall System.Data.SQLite"
  5. Close Visual Studio and delete the Package, bin and obj folders
  6. Restart Visual Studio and restore the packages
  7. Runned the console project -> Does not work due the "corrupted" app.config
  8. Restore the old App.config but change to ""
  9. Runned the console project -> Succeeded

I tried your app.config which also worked for me.
Which error do you get when you are trying to run the project with the "pre-.net4.0* app.config?

Greetings Marc

It's probably something I did after updating the Nuget package references along with the altered "bad" app.config.
In any case I also managed to do it using the VS nuget package manager UI, Without closing VS, deleting the package, bin and obj folders.
I would be glad if you could add a note in the Readme.md file so that other developers would pay attention to the app.config as it is fragile.
You can mark this ticket as closed as far as I'm concerned.
Are you planning on adding this library to Nuget?

Thanks a lot for all the hard work and quick response.
Keep up the good work!
Harel M.

Okay, I'll add a note to the readme file.

Yes since today :) but currently only for .NET 4.5.
https://www.nuget.org/packages/SQLite.CodeFirst/

I'm going to include the link to the NuGet Package into the readme file as well.

NuGet package: ef14064
Hint about app.config: f85bcca

In-Memory Database Connection
This is an example of the in-memory SQLite v3 database connection string to use. It took me a bit of time to track down Pooling=True is needed.

In web.config / app.config

<connectionStrings>

  <add name="memDb" 
    connectionString="Data Source=:memory:;Version=3;Pooling=True;" 
    providerName="System.Data.SQLite.EF6" />

...

(added to this issue because the issue is currently being linked to from the Hint section of the project README.md file; developers will likely reference this area for helpful configuration info)