第一次来这里。我正在尝试使用Visual Studio 2017社区将Entity Framework与PostgreSQL集成:
从Nuget,我安装了这个包:
我的项目是一个带有.NET Framework 4.6.2的Web API(不是核心)
我的web.config
看起来像这样
<system.data>
<DbProviderFactories>
<remove invariant="Npgsql"/>
<add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description="Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Version=4.0.2.0, Culture=neutral, PublicKeyToken=5D8B90D52F46FDA7"/>
</DbProviderFactories>
</system.data>
<entityFramework>
<defaultConnectionFactory type="Npgsql.NpgsqlConnectionFactory, Npgsql"/>
<providers>
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql"/>
</providers>
</entityFramework>
但是,在Nuget Package Manager控制台中,在发出qazxsw poi后,我收到此错误:
检查上下文是否以现有数据库为目标... System.Configuration.ConfigurationErrorsException:无法找到或加载已注册的.Net Framework数据提供程序。
在System.Data.Common.DbProviderFactories.GetFactory(DataRow providerRow)中 在System.Data.Common.DbProviderFactories.GetFactory(String providerInvariantName)中 在System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetService中(类型类型,对象键,Func
Enable Migrations
2 k) 在System.Collections.Concurrent.ConcurrentDictionary3 handleFailedLookup)
2 valueFactory) 在System.Data.Entity.Infrastructure.DependencyResolution.CachingDependencyResolver.GetService(Type type,Object key)中 在System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain。<> c__DisplayClass3.b__0(IDbDependencyResolver r) 在System.Linq.Enumerable.WhereSelectArrayIterator
in System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetService(Type type, Object key)
in System.Data.Entity.Infrastructure.DependencyResolution.CachingDependencyResolver.<>c__DisplayClass1.<GetService>b__0(Tuple2.GetOrAdd(TKey key, Func
1源代码中,Func2.MoveNext()
2.MoveNext() 在System.Linq.Enumerable.FirstOrDefault [TSource](IEnumerable
in System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable2 predicate)
2谓词)中 在System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService(Type type,Object key)中 在System.Data.Entity.Infrastructure.DependencyResolution.CompositeResolver
in System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService(Type type, Object key)
in System.Data.Entity.Infrastructure.DependencyResolution.RootDependencyResolver.GetService(Type type, Object key)
in System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.<>c__DisplayClass3.<GetService>b__0(IDbDependencyResolver r)
in System.Linq.Enumerable.WhereSelectArrayIterator1 source, Func
1解析器中) 在System.Data.Entity.Migrations.DbMigrator..ctor中(DbMigrationsConfiguration配置,DbContext usersContext,DatabaseExistenceState existState,Boolean calledByCreateDatabase) 在System.Data.Entity.Migrations.DbMigrator..ctor中(DbMigrationsConfiguration配置) 在System.Data.Entity.Migrations.Design.MigrationScaffolder..ctor中(DbMigrationsConfiguration migrationsConfiguration) 在System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldRunner.Run()中 在System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)中 在System.AppDomain.DoCallBack(CrossAppDomainDelegate callBackDelegate)中 在System.Data.Entity.Migrations.Design.ToolingFacade.Run(BaseRunner runner)中 在System.Data.Entity.Migrations.Design.ToolingFacade.ScaffoldInitialCreate(String language,String rootNamespace)中 在System.Data.Entity.Migrations.EnableMigrationsCommand。<> c__DisplayClass2。<。ctor> b__0() 在System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action命令)中无法找到或加载已注册的.Net Framework数据提供程序。
你能帮助我吗?
提前致谢。
尝试使用Windows Installer将Npgsql安装到GAC。这可以帮助很多时间。
2.GetService(Type type, Object key)
in System.Data.Entity.Infrastructure.DependencyResolution.DbDependencyResolverExtensions.GetService[T](IDbDependencyResolver resolver, Object key)
in System.Data.Entity.Internal.LazyInternalConnection.CreateConnectionFromProviderName(String providerInvariantName)
in System.Data.Entity.Internal.LazyInternalConnection.InitializeFromConnectionStringSetting(ConnectionStringSettings appConfigConnection)
in System.Data.Entity.Internal.LazyInternalConnection.TryInitializeFromAppConfig(String name, AppConfig config)
in System.Data.Entity.Internal.LazyInternalConnection.Initialize()
in System.Data.Entity.Internal.LazyInternalConnection.get_Connection()
in System.Data.Entity.Internal.LazyInternalContext.get_Connection()
in System.Data.Entity.Infrastructure.DbContextInfo..ctor(Type contextType, DbProviderInfo modelProviderInfo, AppConfig config, DbConnectionInfo connectionInfo, Func
另外,使用以下命令检查Download中的版本号:
DbProviderFactories
并确保它们匹配。
我前段时间使用过本教程typeof(Npgsql.NpgsqlFactory).AssemblyQualifiedName