I'm developing a library in C# and .NET Framework 4.0 and Sqlite.
I have this class:
using MyCompany.Data.Logs.Model;
using MyCompany.Data.Sqlite.Common;
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.SQLite;
using System.Linq;
using System.Text;
namespace MyCompany.Data.Logs.Sqlite.Concrete
{
[DbConfigurationType(typeof(SQLiteConfiguration))]
class LogsDbContext : DbContext
{
public LogsDbContext()
: base("name=Logs")
{
}
//SQLite funciona bien si se utiliza este constructor
public LogsDbContext(string connString)
: base(new SQLiteConnection() { ConnectionString =
new SQLiteConnectionStringBuilder(connString)
.ConnectionString }, true)
{
// If database doesn't exit, don't create it.
Database.SetInitializer<LogsDbContext>(null);
}
public virtual DbSet<LOGS> LOGS { get; set; }
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new MyCompany.Data.Logs.Sqlite.Configurations.LOGConfiguration());
base.OnModelCreating(modelBuilder);
}
}
}
And it doesn't work. I get this exception:
The default DbConfiguration instance was used by the Entity Framework before the 'SQLiteConfiguration' type was discovered. An instance of 'SQLiteConfiguration' must be set at application start before using any Entity Framework features or must be registered in the application's config file. See http://ift.tt/1xxp2nE for more information.
This is my app.config:
<?xml version="1.0" encoding="utf-8"?>
<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>
<startup useLegacyV2RuntimeActivationPolicy="true">
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
</startup>
<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>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Data.SQLite" publicKeyToken="db937bc2d44ff139" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.0.96.0" newVersion="1.0.96.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>
<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>
</configuration>
The strange thing here is that the same code works fine in another computer. First, it executes public LogsDbContext(string connString)
and then protected override void OnModelCreating
.
Any idea about what is happening?
Aucun commentaire:
Enregistrer un commentaire