【发布时间】:2017-09-01 20:16:12
【问题描述】:
第一次来。我正在尝试使用 Visual Studio 2017 社区将实体框架与 PostgreSQL 集成:
从 Nuget,我安装了这个包:
- EntityFramework.6.1.3
- Npgsql.3.2.2
- EntityFramework6.Npgsql.3.1.1
我的项目是一个带有 .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 Packet Manager 的控制台中,发出 Enable Migrations 后,我收到此错误:
检查上下文是否针对现有数据库...
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(类型类型,对象键,Func3 handleFailedLookup)2 k)
in System.Data.Entity.Infrastructure.DependencyResolution.DefaultProviderFactoryResolver.GetService(Type type, Object key)
in System.Data.Entity.Infrastructure.DependencyResolution.CachingDependencyResolver.<>c__DisplayClass1.<GetService>b__0(Tuple
在 System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory)
在 System.Data.Entity.Infrastructure.DependencyResolution.CachingDependencyResolver.GetService(类型类型,对象键)
在 System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.c__DisplayClass3.b__0(IDbDependencyResolver r)
在 System.Linq.Enumerable.WhereSelectArrayIterator2.MoveNext()1 源中,Func
in System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable2 predicate)2.MoveNext()
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.WhereSelectArrayIterator
在 System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable1 source, Func2 谓词)
在 System.Data.Entity.Infrastructure.DependencyResolution.ResolverChain.GetService(类型类型,对象键)
在 System.Data.Entity.Infrastructure.DependencyResolution.CompositeResolver2.GetService(Type type, Object key)1 解析器)
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
在 System.Data.Entity.Migrations.DbMigrator..ctor(DbMigrationsConfiguration 配置,DbContext usersContext,DatabaseExistenceState 存在状态,布尔调用ByCreateDatabase)
在 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(字符串语言,字符串根名称空间)
在 System.Data.Entity.Migrations.EnableMigrationsCommand.c__DisplayClass2.<.ctor>b__0()
在 System.Data.Entity.Migrations.MigrationsDomainCommand.Execute(Action 命令)未能找到或加载已注册的 .Net Framework Data Provider。
你能帮帮我吗?
提前致谢。
【问题讨论】:
标签: c# .net postgresql entity-framework