I'm facing a InvalidCastException (SqliteConnection to EntityConnection) and is driving me crazy because I don't find much information about it and the one I find simply doesn't work.
I guess is something wrong with the app.config file but I've try a lot of things without any result.
Also try changing the DbContext but with the same result, nothing.
Here the app.config file
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"/>
<providers>
<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>
</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" />
<add name="SQLite Data Provider" invariant="System.Data.SQLite" description=".NET Framework Data Provider for SQLite" type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="MailServerDBConnectionString"
connectionString="metadata=http://res*/Database.DatabaseEntities.MailServerDBModel.csdl|res*/Database.DatabaseEntities.MailServerDBModel.ssdl|res*/Database.DatabaseEntities.MailServerDBModel.msl;provider=System.Data.SQLite.EF6;provider connection string="data source=C:\MailServerDB.s3db""
providerName="System.Data.SQLite" />
</connectionStrings>
Here the DbContext:
public MailServerDBConnectionString()
: base("name=MailServerDBConnectionString")
{
}
Here how I use it:
try
{
using (MailServerDBConnectionString context = new MailServerDBConnectionString())
{
var inbound = context.C_DIRECTION.Find("INBOUND");
}
}
catch (Exception crap)
{
throw new Exceptions.DBException("Still not f*cking working", crap);
}
I've try everything and I hope someone has face this problem before, any suggestions is always welcome, thanks for your time.
Aucun commentaire:
Enregistrer un commentaire