1

I try to setup sqllite provider for entity framework from code (w/o web.config). I have prepared DbConfiugration:

using System.Data.Common;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.SQLite.EF6;

namespace Infrastructure
{
    internal class MyDbConfiguration: DbConfiguration
    {
        public MyDbConfiguration()
        {
            SetDefaultConnectionFactory(new LocalDbConnectionFactory("v11.0"));
            SetProviderFactory("System.Data.SQLite.EF6", new SQLiteProviderFactory());
        }
    }
}

But when try to use DbContext, the following error is used:

System.NotSupportedException: '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.

How can I configure EF to use SQLite's provider in code, without using web.config?

pwas
  • 3,225
  • 18
  • 40
  • You're missing the config, as the error says. You should have something like `` in your config. –  Dec 14 '17 at 14:57
  • 1
    [This](https://stackoverflow.com/questions/29129796/no-entity-framework-provider-found-for-ef-6-and-sqlite-1-0-96-0) post has a similar title, it may help. – dcg Dec 14 '17 at 14:58
  • @Amy I see, but the question is that can I set it programatically w/o web.config? – pwas Dec 14 '17 at 15:01
  • Your question was "what am i missing", not "can i do this without web.config". To answer the new question, maybe. Everyone does it with configuration though. You might be hard pressed to find an example of someone doing it in code. –  Dec 14 '17 at 15:08
  • @Amy it is cleary written that I'd like to run EF from code (w/o web.config) -see first line. – pwas Dec 14 '17 at 15:09
  • I've edited your question to ask what you meant to ask, since what you actually asked wasn't what you were after. –  Dec 14 '17 at 15:11
  • Is `MyDbConfiguration` in the same assembly as your DbContext? – mason Dec 14 '17 at 15:16
  • @mason yes. I have also tried to set hack from question linked by dcg, but the same error occurs. – pwas Dec 14 '17 at 15:17
  • If you were configuring Oracle, you would call `SetProviderServices` and pass `EFOracleProviderServices.Instance` as shown [here](https://docs.oracle.com/cd/E56485_01/win.121/e55744/InstallEntityConfig.htm#ODPNT8266). Perhaps there's an equivalent you can do for SQLite? Just brainstorming here. That led me to [this question](https://stackoverflow.com/questions/29904193/create-sqlite-database-using-entity-framework). – mason Dec 14 '17 at 15:20
  • How about [EF6, SQLite won't work without App.confg](https://stackoverflow.com/questions/43615926/ef6-sqlite-wont-work-without-app-confg/43688403#43688403) – Ivan Stoev Dec 15 '17 at 07:39

0 Answers0