SQLite EF6 programmatically set connection string at runtime

后端 未结 3 568
情话喂你
情话喂你 2020-12-05 00:51

I try to migrate form EF 3.5 to 6 (with SQLite as database). We can not set the connection string in the app config file (this works without problems with ef6). We have to s

3条回答
  •  攒了一身酷
    2020-12-05 01:19

    After looking at this further it seems the problem is that there isn't a IDbConnectionFactory defined for SQLite. So another approach would be to define your own factory implementation.

    public class SQLiteConnectionFactory : IDbConnectionFactory
    {
        public DbConnection CreateConnection(string connectionString)
        {
            return new SQLiteConnection(connectionString);
        }
    }
    

    Then replace the defaultConnectionFactory entry in your 'app.config' with something like:

    
    

提交回复
热议问题