Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite with EF Code First

After my success using SQLite with NHibernate, I am very happy to use it for testing with Entity Framework Code First.

If you have some example connections string and set up demos, that would be great and save a bit of time from my hectic day.

Thanks a lot.

EDIT:

Worth mentioning that I am getting this error during debugging when applying crud actions via the EF "data context":

Unable to determine the provider name for connection of type 'System.Data.SQLite.SQLiteConnection'.

<system.data>
    <DbProviderFactories>
        <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>


<connectionStrings>
    <add name="DataContext"
         connectionString="Data Source=:memory:;Version=3;New=True;"
         providerName="System.Data.SQLite"
     />
</connectionStrings>

Hopefully EF does integrate with SQLite in this fashion. Although the error message, alarmingly, suggests probably not.

like image 235
nick Avatar asked Dec 13 '10 12:12

nick


People also ask

Can I use Entity Framework with SQLite?

This database provider allows Entity Framework Core to be used with SQLite. The provider is maintained as part of the Entity Framework Core project.


1 Answers

You need to use the assembly qualified name:

<add name="SQLite Data Provider" 
     invariant="System.Data.SQLite" 
     description=".Net Framework Data Provider for SQLite" 
     type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.66.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
like image 195
Max Toro Avatar answered Sep 22 '22 12:09

Max Toro