2

I can't configurate App.config. I have error

  • base {"Unable to determine the provider name for provider factory of type 'System.Data.SQLite.SQLiteFactory'. Make sure that the ADO.NET provider is installed or registered in the application config."} System.SystemException {System.NotSupportedException}

My code:

class Program
{
    static void Main(string[] args)
    {
        new Program();
    }

    public Program()
    {
        CustomerContext cc = new CustomerContext();

        cc.Customers.Add(new Customer() { Name = "sdf", LastName = "dfs" });
    }

}

public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string LastName { get; set; }
}

public class CustomerContext : DbContext
{

    public DbSet<Customer> Customers { get; set; }
}

And App.config

<?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>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>
  <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" />
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="System.Data.SQLite" />
      <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="CustomerContext" connectionString="Data Source=test.sqlite" providerName="System.Data.SQLite.EF6" />
  </connectionStrings>
</configuration>

File test.sqlite is added to project also EF and SQLite are added by nuget

DamianM
  • 468
  • 1
  • 6
  • 15
  • Maybe my answer here helps (watch the video) : http://stackoverflow.com/questions/25089346/database-first-create-entity-framework-6-1-1-model-using-system-data-sqlite-1-0 – TomL Sep 09 '14 at 08:47
  • @TomL I doing everything like in the video, but when I i click Tools->Connect to Database I dont have Sqlite in data source [screen](http://i62.tinypic.com/28w19o3.png) – DamianM Sep 09 '14 at 12:22
  • Which version of Visual Studio are you using? The explanation and video is for VS 2013 Professional. Express editions probably won't work and for 2012 you probably need to download sqlite-netFx45-setup-bundle-x86-2012-1.0.93.0.exe and target the 4.5 framework. – TomL Sep 10 '14 at 09:24
  • 2013 Express, but I solved this already by using VS2010 and its work fine without your "magic", just install everything by nuget. – DamianM Sep 10 '14 at 15:19
  • The 'magic' apparently doesn't work for Express editions, but good that you got it working. I hope a new System.Data.SQLite update improves things... – TomL Sep 11 '14 at 09:09

1 Answers1

0

Comment out the following:

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
  </startup>

Also, is Entity Framework (edmx file) defined within your Application project or is it defined within a separate class library?

If it is in a separate class library, then copy the xml within your app config file of your class library project into the app config file of your app project.

Update:

Last time I checked, SQLite must be defined within your app project and NOT a separate class library.

Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118