我正在 Visual Studio 2012 Update 4 中使用 EntityFramework 6.1.1 和 npgsql 2.2.3 开发一个项目。 为此,我使用提供的设置安装了 npgsl,并安装了 nuget 包“Npgsql”和“Npgsql for Entity Framework”(以及当然是“EntityFramework”本身)。
过去一切都很好:我可以成功访问我的数据库一段时间 - 直到有一天一切都“爆炸”。
这是事件历史:
- Fixing compiler errors after a major code upgrade I encountered these error messages:
- “无法加载 npgsl.EntityFrameworkLegacy 程序集”(我既没有安装也没有引用此程序集)
- 一大堆“找不到元数据文件‘xxx’”错误,其中‘xxx’引用了我自己的所有项目程序集
- 我找到了“元数据文件”问题的可能解决方案 - 例如删除 .suo 文件、检查项目构建顺序等。他们都没有解决问题。所以我删除了
我的项目中的 .edmx 文件(以及所有自动生成的数据库访问文件)。这解决了“元数据文件”问题 - 当然引入了“未解析的符号”。
- 我尝试向我的项目添加新的“ADO.NET 实体数据模型”以重新获得数据库访问权限。只有所有 PostgreSQL 数据库连接不再在连接列表中列出。
另外,我无法创建新的 PostgreSQL 连接,因为未列出此数据源。虽然这并不影响全局“数据连接”对话框
Visual Studio:在这里我仍然可以访问我的 PostgreSQL 连接。
- 我使用安装程序重新安装了 npgsql。现在我可以创建一个新的“ADO.NET 实体数据模型”并连接到我的 PostgreSQL 数据库。但这一次我收到错误消息:
”您的项目引用了最新版本的实体框架;但是,找不到与此版本兼容的实体框架数据库提供程序[...]“。 这是
我现在被困在哪里。
我当前的设置是:
- the project refers to the following assemblies:
- 适用于 .NET 4.5 的实体框架 6.1.1
- .NET 4.5 的 EntityFramework.SqlServer 6.1.1
- 适用于 .NET 4.5 的 Npgsql 2.2.3
- 适用于 .NET 4.5 的 Npgsql.EntityFramework 2.2.3
- 这是我的应用程序配置:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
</providers>
</entityFramework>
</configuration>
- 我的 machine.config 中有这个(32 位和 64 位):
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Version=2.2.3.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" support="FF" />
</DbProviderFactories>
</system.data>
当然,在添加新模型之前我尝试重建我的解决方案。但这没有帮助。
还有其他我可能错过的配置问题吗?
谁能向我解释一下为什么会发生这一切?