dimanche 2 août 2015

Unable to determine the provider name for provider factory of type

I want to use sqlite entity framework in my web api project, but it always can't work well,

here is my development enviroment.

1.Visual studio 2013, .net framework 4.5

  1. sqlite package version is 1.0.97, I installed below packages

    system.data.sqlite, system.data.sqlite.ef6, system.data.sqlite.linq

  2. EntityFramework is 6.1.3

Here is exception that I got

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

Here is my webconfig

<configuration>
  <configSections>
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
    <!-- For more information on Entity Framework configuration, visit http://ift.tt/1eigFsq -->
  </configSections>

  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="mssqllocaldb" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="System.Data.SQLite.EF6" type="System.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6" />  <!--type="System.Data.SQLite.EF6.SQLiteProviderServices-->
    </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" />
    </DbProviderFactories>
  </system.data>
  <connectionStrings>
    <add name="Sqlite" connectionString="data source=&quot;D:\MyWebAPI\src\MyWeb.Api\App_Data\sqlite_test.db&quot;" providerName="System.Data.SQLite.EF6" />
  </connectionStrings>
</configuration>

I can connect sqlite database file through "connect to database" in tool of visual studio, I also can generate entity using code first.

but I can't get data normal

Here is my code

 public partial class Sqlite : DbContext
    {
        public Sqlite()
            : base("name=Sqlite")
        {
        }

        public virtual DbSet<AuthorizationLog> AuthorizationLogs { get; set; }
        public virtual DbSet<Checksum> Checksums { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Entity<AuthorizationLog>()
                .Property(e => e.ClientKey)
                .IsUnicode(false);

            modelBuilder.Entity<AuthorizationLog>()
                .Property(e => e.Login)
                .IsUnicode(false);

            modelBuilder.Entity<AuthorizationLog>()
                .Property(e => e.Password)
                .IsUnicode(false);

            modelBuilder.Entity<AuthorizationLog>()
                .Property(e => e.ConnectionString)
                .IsUnicode(false);
        }
    }
   public class ValuesController : ApiController
    {
        // GET api/values
        Sqlite ctx = new WebApi2Demo.Sqlite();
        public IEnumerable<Checksum> Get()
        {
            return ctx.Checksums;
        }
        }

Aucun commentaire:

Enregistrer un commentaire