Answer the question
In order to leave comments, you need to log in
SQLite Entity Framework 6. Can't find provider. Does not create a table, even if it creates a database. What is the reason?
What am I doing wrong? Is there an error somewhere in the config? Project attached. The option with Sql Server LocalDb works, but not with SQLite.
Download project for 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; }
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question