1.用nuget安装npgsql和EF

注意,Nuget一定要安装Npgsql的2.2.7版本,更高版本nuget在后面安装EF的时候无法自动解析。

install-Package Npgsql -Version 2.2.7

install-package Npgsql.EntityFramework

2.给app.config增加DbProviderFactories

注意红字部分,nuget不会自动增加,需要手工增加,否则会报异常:

The ADO.NET provider with invariant name 'Npgsql' is either not registered in the machine or application config file, or could not be loaded

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>

<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>

<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
</providers>

</entityFramework>

<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider" invariant="Npgsql" description="Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql" />
</DbProviderFactories>
</system.data>

<connectionStrings>
<add name ="PostgreSqlDb" connectionString ="server=127.0.0.1;User Id=user;password=pwd;database=dbname" providerName="Npgsql"/>
</connectionStrings>
</configuration>

3.坑

如果程序跑起来报以下错误,在确定安装了正确版本的PostgreSqlDb Data Provider之后,请检查.net framework的版本是否正确。比如没安装.net framework 4.5。

Method not found: 'System.Data.Common.DbProviderFactory System.Data.Common.DbProviderFactories.GetFactory(System.Data.Common.DbConnection)'.

EF连接PostgreSql的更多相关文章

  1. 使用EF连接Postgresql

    环境: VS2017 Community Windows 10 Postgresql 9.6 安装Postgresql: https://www.postgresql.org/download/ 1. ...

  2. Entity Freamwork 6连接PostgreSql数据库

    原文 Entity Freamwork 6连接PostgreSql数据库 开发环境 VS 2015  Update 1   Postgre Sql 9.4 使用过程 1.使用Nuget在项目中添加对E ...

  3. C#使用EF连接PGSql数据库

    前言 由于项目需要,使用到了PGSql数据库,说实话这是第一次接触并且听说PGSql(PostgreSQL)关系型数据库,之前一直使用的都是SqlServer,一头雾水的各种找资源,终于将PGSql与 ...

  4. ASP.NET MVC 使用 Petapoco 微型ORM框架+NpgSql驱动连接 PostgreSQL数据库

    前段时间在园子里看到了小蝶惊鸿 发布的有关绿色版的Linux.NET——“Jws.Mono”.由于我对.Net程序跑在Linux上非常感兴趣,自己也看了一些有关mono的资料,但是一直没有时间抽出时间 ...

  5. EF 连接sql2000

    正常连接会提示版本低 可以先用ef连接高版本的sql然后新建好EDMX文件后,在右键xml方式打开,把ProviderManifestToken="2008" 改为2000 然后再 ...

  6. EF 连接MySQL 数据库  保存中文数据后乱码问题

    EF 连接MySQL 数据库  保存中文数据后乱码问题 采用Code First 生成的数据库,MySQL数据库中,生成的表的编码格式为***** 发现这个问题后,全部手动改成UTF8(图是另一个表的 ...

  7. 视频教程--ASP.NET MVC 使用 Petapoco 微型ORM框架+NpgSql驱动连接 PostgreSQL数据库

    说好的给园子里的朋友们录制与<ASP.NET MVC 使用 Petapoco 微型ORM框架+NpgSql驱动连接 PostgreSQL数据库> 这篇博客相对应的视频,由于一个月一来没有时 ...

  8. kali linux 系列教程之metasploit 连接postgresql可能遇见的问题

    kali linux 系列教程之metasploit 连接postgresql可能遇见的问题 文/玄魂   目录 kali linux 下metasploit 连接postgresql可能遇见的问题. ...

  9. EF连接mysql数据库生成实体模型

    声明:本人也是第一次用EF连接mysql生成实体模型 经过试验: mysql-connector-net-6.6.6 可以支持VS2012 mysql-connector-net-6.3.9 可以支持 ...

随机推荐

  1. VadRoot枚举进程模块在Windows7下的完整实现

      原理小伟的小伟在http://bbs.pediy.com/showthread.php?t=66886说的挺清楚了,Windows7下有一些变化,使用NtQueryVirtualMemory来枚举 ...

  2. ROS学习(二)—— 配置ROS环境

    一.管理环境 p { margin-bottom: 0.25cm; line-height: 120% } a:link { } 如果你在查找和使用ROS软件包方面遇到了问题,请确保你已经正确配置了脚 ...

  3. MySQL数据库1067 问题

    1.MySql1067错误解决方法 http://blog.csdn.net/mhmyqn/article/details/17043921   MySql 1045解决方法 my.ini  mysq ...

  4. mysql5.7绿色版安装与配置

    1,找到zip archive包下载,官方地址如下: http://dev.mysql.com/downloads/mysql/ http://dev.mysql.com/downloads/file ...

  5. Orcale 数据库客户端PL/SQL中文乱码的问题

    http://jingyan.baidu.com/article/948f59242aa519d80ef5f96e.html

  6. iframe框架用法

    1.iframe标签: <iframe src="demo1.html" name="qiuqiu_Page" frameborder="0&q ...

  7. 第三周作业(一):安装VS以及创建单元测试

    安装的时候找的是最新版本的VS2015,因为不想花钱也不想用破解版,所以用社区版本. 下了一个IOS文件,社区版VS2015,个人免费版,强行表示不用盗版来表现自己高尚的情操:D 放入虚拟光驱软件后, ...

  8. 弹出popwindow 背景变暗

    先看下效果图吧 代码如下 package com.example.administrator.popwindowdemo.view; import android.app.Activity; impo ...

  9. 简单的jquery选项卡效果

    html部分 <ul class="tab"> <li>最新</li> <li class="cur">热门&l ...

  10. Django models知识小点

    django 为使用一种新的方式,即关系对象映射(ORM) 一,创建表 1,基本结构 注意: 1,创建标的时候,如果我们不给表加自增列,生成表的时候会默认给我们生成一列为ID的自增列,当然我们也可以自 ...