Entity Framework connection string not from config

前端 未结 4 869
眼角桃花
眼角桃花 2020-12-23 22:43
public class Context : DbContext
{
    public Context(string connString) : base(connString) 
    {
        Database.SetInitializer(new MyContextInitializer());
    }         


        
4条回答
  •  别那么骄傲
    2020-12-23 23:09

    In my case (exactly the same error) it was solved by changing the default connection factory:

    Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");
    

    Leave out any reference to provider in your connection string because it isn't necessary (this way). I think I read that by default the Database.DefaultConnectionFactory is set to SqlConnectionFactory() but I can't find a reference for that.

提交回复
热议问题