'No Entity Framework provider found' for EF 6 and SQLite 1.0.96.0

后端 未结 6 1062

I realize there are already several similar questions on this topic, but many of them are from older version of SQLite which did not fully support EF 6 as far as I am aware.

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-12 22:47

    public class EFConfiguration : DbConfiguration
    {
        public EFConfiguration()
        {
            SetDefaultConnectionFactory(new LocalDbConnectionFactory("v.11"));
    
            //HACK
            var EF6ProviderServicesType = typeof(System.Data.SQLite.EF6.SQLiteProviderFactory).Assembly.DefinedTypes.First(x => x.Name == "SQLiteProviderServices");
            var EF6ProviderServices = (DbProviderServices)Activator.CreateInstance(EF6ProviderServicesType);
            SetProviderServices("System.Data.SQLite.EF6", EF6ProviderServices);
            SetProviderServices("System.Data.SqlClient", System.Data.Entity.SqlServer.SqlProviderServices.Instance);
            SetProviderFactory("System.Data.SQLite.EF6", System.Data.SQLite.EF6.SQLiteProviderFactory.Instance);
            SetProviderFactory("System.Data.SQLite", System.Data.SQLite.SQLiteFactory.Instance);
        }
    }
    

提交回复
热议问题