Casper-SC
@Casper-SC
Программист (.NET)

SQLite Entity Framework 6. Не находит провайдер. Не создаёт таблицу, если даже создаёт БД. В чём причина?

Что я делаю не так? Где-то в конфиге ошибка? Проект прикрепил. Вариант с Sql Server LocalDb работает, а с SQLite нет.
Скачать проект для Visual Studio

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit [url]http://go.microsoft.com/fwlink/?LinkID=237468[/url] -->
    <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>
  <system.data>
    <!--
        NOTE: The extra "remove" element below is to prevent the design-time
              support components within EF6 from selecting the legacy ADO.NET
              provider for SQLite (i.e. the one without any EF6 support).  It
              appears to only consider the first ADO.NET provider in the list
              within the resulting "app.config" or "web.config" file.
    -->
    <DbProviderFactories>
      <add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
      <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>
  <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" />
    </providers>
    
  </entityFramework>
 
  <connectionStrings>
    <add name="ImagesContext" connectionString="Data Source=E:\Прочее\Базы данных\ViRus.db" providerName="System.Data.SQLite.EF6" />
  </connectionStrings>
</configuration>


using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
 
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            using (SQLiteContext context = new SQLiteContext())
            {
                //try
                //{
                context.Database.CreateIfNotExists();
                context.Pictures.Add(new Picture { Key = "picture1", FileName = "----" });//, Bytes = new byte[] { 0, 23, 54, 230 } });
                context.SaveChanges();
                Console.WriteLine("Сохранено");
                //}
                //catch (Exception e)
                //{
                //    Console.WriteLine(e);
                //}
            }
 
            Console.WriteLine("Конец");
            Console.ReadKey();
        }
    }
 
    public class SQLiteContext : DbContext
    {
        private const string dbName = @"E:\Прочее\Базы данных\ViRus.db";
        private static readonly string connectionString =
            string.Format(@"Data Source={0};", dbName);
 
        public SQLiteContext()
            : base("ImagesContext")
        {
 
        }
 
        public DbSet<Picture> Pictures { get; set; }
    }
 
    [Table("Pictures")]
    public class Picture
    {
        [Key]
        public string Key { get; set; }
 
 
        public string FileName { get; set; }
        //public byte[] Bytes { get; set; }
    }
}


711c6a224879429a981924f57b34482b.jpg6fcc75e076a84891afc463750510142c.jpg
  • Вопрос задан
  • 4256 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы