3

I am using Entity Framework 4 code first method to automatically create SQLite database, I get an error telling me ProviderIncompatibleException:

[System.Data.ProviderIncompatibleException] = {"CreateDatabase is not supported by the provider."}

I thaught EF 4 support it?

I am using this in app.config:

<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, Version=1.0.81.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </DbProviderFactories>
  </system.data>

Thank you.

Alvin
  • 8,219
  • 25
  • 96
  • 177
  • 3
    Have you checked out this thread that seems to answer your question? http://stackoverflow.com/a/8522174/325521 – Shiva Aug 29 '12 at 03:09

3 Answers3

3

Support of both Code-First ( the CreateDatabase() method you mentioned) and Code-First Migrations (a newer approach to Code-First development) is implemented at the level of a certain EF-provider. In case of System.Data.SQLite all this functionality is not implemented in the provider. If you need it, you should use other EF-providers. For example, Devart dotConnect for SQLite supports both Code-First and Code-First Migrations.

Devart Team

Devart
  • 119,203
  • 23
  • 166
  • 186
  • 1
    @KevFixx The free, standard edition of dotConnect for SQLite does not support EF at all. The professional edition supports EF including both Code First and Migrations. – bricelam Oct 15 '12 at 16:21
1

It's often caused by compatibility issue between .NET 2 agaisnt which SQLite data provider was built and .NET 4 you are actually using.

Take a look at this link, it should give you the answer: system.data.sqlite .net 4

Note that you have to apply this in your app.config or web.config where your model is located but also in your entrypoint project (your .exe, or asp.net project for example).

Community
  • 1
  • 1
Guillaume
  • 1,782
  • 1
  • 25
  • 42
0

@Kev Fixx: If you're using SQLite provider from https://system.data.sqlite.org/‎, then it doesn't support Migrations (such as Create Database). You can use a commercial one (like from Devart) or you write your own Migration. This article uses the concept from Android to make a simple Migration strategy http://hintdesk.com/sqlite-with-entity-framework-code-first-and-migration/ . Take a look if it helps you.