【发布时间】:2015-11-09 19:44:13
【问题描述】:
我通过直接使用 npgsql 成功访问了现有的 postgresql 数据库。我用这个:
- PostgreSQL 9.0.10(32 位)
- Visual Studio 2015 社区(64 位)
- NpgSql 2.2.5(通过管理 Nuget 包)
然而,dbase 有 25 多个表和 400 多个列,因此我的意图是使用实体框架 + .ADO.net 实体数据模型来避免必须对所有列进行代码访问。我搜索并尝试了这个站点上的所有内容,npgsql 站点http://www.npgsql.org/doc/ddex.html,...但我没有成功生成 .ADO.net 实体数据模型,因为 postgresql 没有出现在数据源中。
我用于这个:
- PostgreSQL 9.0.10(32 位)
- Visual Studio 2015 社区(64 位)
- NpgSql 2.2.5(通过管理 Nuget 包)
- Setup_Npgsql-2.2.5.0-r3-net45.exe(来自 GitHub,因为某些网站 表示要求在 GAC 中具有相同的版本 作为visual studio项目中使用的包;我没有拿版本 3.0.0 因为 Github 缺少安装文件)。
- Npgsql.entityframework6 2.2.5(通过管理 Nuget 包)
- Entityframework 6.1.3(通过管理 Nuget 包)
在尝试生成 .ADO.net 实体数据模型时,我该怎么做才能使 postgresql 显示为数据源?
还是 Visual Studio 2015 社区不允许为 postgresql 生成 .ADO 网络实体数据模型?
编辑 我添加了以下信息,希望得到回复:
使用 Microsoft Windows 8.1 6.3.9600 build 9600 64 位
提取“C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config”
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Version=2.2.5.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" support="FF" />
</DbProviderFactories>
</system.data>
提取“C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config”
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Version=2.2.5.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" support="FF" />
</DbProviderFactories>
</system.data>
“Visual Studio - packages.config”
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="EntityFramework" version="6.1.3" targetFramework="net452" />
<package id="Npgsql" version="2.2.5" targetFramework="net452" />
<package id="Npgsql.EntityFramework" version="2.2.5" targetFramework="net452" />
</packages>
“Visual Studio - App.config”
<?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>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
【问题讨论】:
-
我在 VS 2015 中遇到了同样的问题,我做了与你几乎相同的事情,但我无法让 postgres 出现。我什至安装了 dotConnect express 版本的 postgres,但没有成功。
-
我能理解你,但我仍然有这个问题。作为 C# 中的初学者,我对此无能为力。我想我别无选择,然后继续学习/尝试最终发现一些明显的东西。
-
这让我做了好几个星期的噩梦。祝你好运。我最终通过创建一大堆函数来执行我的数据操作来解决它。
-
大家好——我在使用 npgsql 时也没有看到数据提供者。你们中的任何一个人都设法找到了解决方案——如果你能发布结果,全世界都会非常感激。克里斯
标签: c# postgresql entity-framework-6 visual-studio-2015 npgsql