Visual Studio Support (DDEX)
原文 VS2012,VS2013,and VS2015Pro+NpgsqlDdexProvider+EFv6 how to(by @kenjiuno)
Reference: #213
Overview
- Install Npgsql DDEX (Data Designer Extensibility) provider.
- Install Npgsql ADO.NET Data Provider.
- Visual Studio’s Entity Data Model wizard will be enabled for PostgreSQL servers.
Prerequisites
Visual Studio 2015 users:
- Visual Studio 2015 Professional or greater editions. Express edition won’t work.
- Microsoft Visual Studio 2015 Update 1 is available.
Visual Studio 2013 users:
- Visual Studio 2013 Professional Update 2 or greater editions. Express edition won’t work.
- Microsoft Visual Studio 2013 Update 5 is available.
Visual Studio 2012 users:
- Visual Studio 2012 Professional or greater editions. Express edition won’t work.
- Visual Studio 2012 Update 5 is available.
PostgreSQL server installed:
- Tested on PostgreSQL 9.3.4 (win-x64)
Install DDEX provider (Npgsql 3.0.x)
- Grab Setup_NpgsqlDdexProvider.exe from https://github.com/npgsql/npgsql/releases and run it.
- Select all components to install.
Note: The version among Npgsql, EntityFramework6.Npgsql and NpgsqlDdexProvider must be same. For example, if you select Npgsql 3.0.5, it needs EntityFramework6.Npgsql 3.0.5. Also NpgsqlDdexProvider 3.0.5.
Install Npgsql ADO.NET Data Provider to Visual Studio (Npgsql 3.0.x)
- Launch Visual Studio.
- Open [TOOL] menu, and then click [Setup Npgsql DbProviderFactories…]
- Click [OK], 2 times.
- Restart Visual Studio.
It asks permission to modify your devenv.exe.config:

This process will add the Npgsql in devenv.exe.config:
<system.data>
<DbProviderFactories>
...
<remove invariant="Npgsql" />
<add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Version=3.0.0.0, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />
</DbProviderFactories>
</system.data>
Setup succeeded.

Note: It will be prompted if administrative privilege is required to modify your devenv.exe.config.
Prepare new project for testing
- Launch Visual Studio.
- [FILE]→[New]→[Project…]
- [Console Application]
- Name is [testef] for example.
Install Npgsql for Entity Framework 6 (3.0.x) from NuGet
- Right click project [testef]
- [Managet NuGet Packages…]
- Type “Npgsql” at [Search Online (Ctrl+E)]
- Install “Npgsql for Entity Framework 6” (EntityFramework6.Npgsql). Version is 3.0.5 for now.
- EntityFramework 6.0.0 and Npgsql are also installed as part of its dependency.
Notice: The assembly versions of Npgsql and NpgsqlDdexProvider must be same. If, for some reason, you need to install a version which isn’t the latest one from NuGet, you need to use the following command in the NuGet Package Manager Console:
Install-Package EntityFramework6.Npgsql -Version <version> where <version> is the version you want to install. A list of versions available can be found in the NuGet Npgsql page: https://www.nuget.org/packages/Npgsql/
Add Npgsql EFv6 provider
Notice: Recent EntityFramework6.Npgsql NuGet package automatically does this process.
- Open [App.config], or [Web.config] for web projects.
- Add provider-element into providers-element:
<provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
An App.config having Npgsql EFv6 privoder:
<?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>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<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, EntityFramework6.Npgsql" />
</providers>
</entityFramework>
</configuration>
Add Npgsql ADO.NET Data Provider
You need to declare the Npgsql ADO.NET Data Provider. Edit one of following config files:
App.configorWeb.configmachine.config
If you are using NuGet for your application, we recommend to edit: App.config or Web.config
machine.config are placed in these locations. Framework64 will exist on 64-bit Windows:
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\machine.config
This is needed part of App.config:
<system.data>
<DbProviderFactories>
<remove invariant="Npgsql"/>
<add name="Npgsql Data Provider"
invariant="Npgsql"
description=".Net Data Provider for PostgreSQL"
type="Npgsql.NpgsqlFactory, Npgsql, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7"
support="FF" />
</DbProviderFactories>
</system.data>
Note: <remove invariant="Npgsql"/> is important, in case of already having <add invariant="Npgsql" ... /> in machine.config.
Edited App.config:
<?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>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<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, EntityFramework6.Npgsql" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<remove invariant="Npgsql"/>
<add name="Npgsql Data Provider"
invariant="Npgsql"
description=".Net Data Provider for PostgreSQL"
type="Npgsql.NpgsqlFactory, Npgsql, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7"
support="FF" />
</DbProviderFactories>
</system.data>
</configuration>
Build once
- Build your project.
New ADO.NET Entity Data Model
- Right click project [testef]
- [Add]→[New Item…]
- [ADO.NET Entity Data Model]
- Default name [Model1] for example.
- Click [Add]
- [EF Designer from database] at Choose Model Contents.

- [New Connection] at Choose Your Data Connection.

- [PostgreSQL Database] at Change Data Source.

- Fill properties in Connection Properties. It is easy to fill everything by setting [ConnectionString].

My sample ConnectionString:
Host=127.0.0.1;Port=5432;Database=npgsql_tests;Username=npgsql_tests;Password=npgsql_tests
Note: PreloadReader and Compatible properies are obsoleted since Npgsql 3.0.0. Please remove them before submitting ConnectionString.
Select [Yes, include the sensitive data in the connection string.] in this case for easy setup.

Select tables which you want, at Choose Your Database Objects and Settings.

Note: remember the text npgsql_tests_efModel at [Model Namespace].
Click OK for Security Warning. T4 Templates generator warns you as it contains just runnable C# code.

You will get a generated model.

Edit your program.cs
Just my sample code for npgsql_tests_ef database.
About the name of “npgsql_tests_efEntities” class, check your [Model Namespace] entered above. Replace “Model” with “Entities”, like it is “npgsql_tests_efModel”.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace testef
{
class Program
{
static void Main(string[] args)
{
using (npgsql_tests_efEntities Context = new npgsql_tests_efEntities())
{
foreach (Blogs blog in Context.Blogs)
{
Console.WriteLine(blog.BlogId + " " + blog.Name);
}
}
}
}
}
Sample output:
How to check if Npgsql DDEX is working correctly. (Npgsql 3.0.x)
(by @kenjiuno)
Reference: #718
NpgsqlDdexProvider 3.0.4 and later has a feature to check Npgsql installation status of your .NET project.
- Right click your .NET project
- Click [Check Npgsql project installation]

Click a button to start the check!

It will suggest them if you need one or more actions:

[Test and result] shows test cases and their results:

How to check if Npgsql DDEX was correctly loaded. (Npgsql 2.x)
(by @kenjiuno)
Reference: #67
Here are tips to check.
Check your connection dialog:

Make sure to edit both x86 and x64’s machine.config. VS2013 runs 64bit mode on x64 machine. C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\machine.config 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.0.12.91, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7"
support="FF" />
</DbProviderFactories>
</system.data>
Note that the Version attribute above should match the version of the Npgsql Assembly you are using.
NpgsqlDdexProvider build tips
(by @kenjiuno)
Reference: #213
VS2010 users
You’ll need VS2010 Professional or greater.
SP0 users:
- Install: Visual Studio 2010 SDK
SP1 users:
- Install: Microsoft Visual Studio 2010 Service Pack 1 (Installer)
- Install: Visual Studio 2010 SP1 SDK
If you need newer NpgsqlDdexProvider2010.pkgdef, create your own manually. pkgdef is a kind of registry file for our DDEX registration. Note: It is needed only if you change contents of NpgsqlDataProviderRegistration class.
Command example:
H:\Dev\Npgsql\NpgsqlDdexProvider>"H:\Program Files (x86)\Microsoft Visual Studio 2010 SDK SP1\VisualStudioIntegration\Tools\Bin\CreatePkgDef.exe" /out=NpgsqlDdexProvider2010.pkgdef /codebase bin\Release-net40\NpgsqlDdexProvider.dll
Output:
Visual Studio (R) PkgDef Creation Utility.
Copyright (c) Microsoft Corporation. All rights reserved.
CreatePkgDef : warning : The Assembly specified at 'bin\Release-net40\NpgsqlDdexProvider.dll' cannot be loaded because an alternate copy with the same identity
exists in the Assembly probing path at 'H:\Dev\Npgsql\NpgsqlDdexProvider\bin\Release-net40\NpgsqlDdexProvider.dll'. The Assembly at 'H:\Dev\Npgsql\NpgsqlDdexPro
vider\bin\Release-net40\NpgsqlDdexProvider.dll' will be loaded instead.
Assembly: NpgsqlDdexProvider 1.0.0.0
Output file: NpgsqlDdexProvider2010.pkgdef
インストールされている製品: NpgsqlDdexProviderPackage、Version 1.0
パッケージ: NpgsqlDdexProviderPackage {958b9481-2712-4670-9a62-8fe65e5beea7}
サービス: PostgreSQL Provider Object Factory
SUCCEEDED: NpgsqlDdexProvider
Check: How to create a pkgdef file for your Visual Studio Packagehttp://blogs.msdn.com/b/dsvst/archive/2010/03/08/how-to-create-a-pkgdef-file-for-your-visual-studio-package.aspx
VS2012 users
You’ll need VS2012 Professional or greater.
- Install: Microsoft Visual Studio 2012 SDK
- Install: Visual Studio 2012 Update 4
VS2013 users
You’ll need VS2013 Professional or greater.
- Install: Microsoft Visual Studio 2013 SDK
- Install: Visual Studio 2013 Update 2 or later.
VS2015 users
You’ll need VS2015 Professional or greater.
How to debug Npgsql DDEX extension
In order to debug it, you will need to use the Experimental Instance of Visual Studio.
- In the NpgsqlDdex project, right click and select properties.
- Go to Debug tab
- Click on the radio button for Start External Program. Point it to the devenv.exe binary. On my machine it’s located at
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\devenv.exe
Then set the command line arguments to /rootsuffix Exp
Save everything and now, just right click the NpgsqlDdex project -> Debug -> Run in a new instance. A new Visual Studio instance should be run where the extension will be made available and you can debug it in the first visual studio instance.
Reference: http://stackoverflow.com/questions/9281662/how-to-debug-visual-studio-extensions
Visual Studio Support (DDEX)的更多相关文章
- Oleg Sych - » Pros and Cons of T4 in Visual Studio 2008
Oleg Sych - » Pros and Cons of T4 in Visual Studio 2008 Pros and Cons of T4 in Visual Studio 2008 Po ...
- Pros and Cons of T4 in Visual Studio 2008
Oleg Sych - » Pros and Cons of T4 in Visual Studio 2008 Pros and Cons of T4 in Visual Studio 2008 Po ...
- VS 远程调试之 “The visual studio remote debugger does not support this edition of windows”
The error message "The visual studio remote debugger does not support this edition of windows&q ...
- News: Visual Studio Code support debugging Linux Apps
http://arstechnica.com/information-technology/2015/11/visual-studio-now-supports-debugging-linux-app ...
- CMake support in Visual Studio
Visual Studio 2017 introduces built-in support for handling CMake projects. This makes it a lot simp ...
- HTML5 Support In Visual Studio 2010
最近HTML5浪潮已经开始了,VS2010已经有一个扩展支持在HTML5智能提示.你可以从这里下载这个扩展: http://visualstudiogallery.msdn.microsoft.com ...
- Create an offline installation of Visual Studio 2017 RC
Create an offline installation of Visual Studio 2017 RC 2016年12月7日 ...
- 安装MySql for Visual Studio的坑
阅读目录 问题描述 解决过程 解决方案 总结 回到顶部 问题描述 安装MySql for Visual Studio 一般来说是为了能在VS的服务器数据连接的数据源中能选择MySql类型,如下图: 但 ...
- 【转载】保哥 釐清 CLR、.NET、C#、Visual Studio、ASP.NET 各版本之間的關係
我常常不仅仅逛 博客园,还会去找国外,特别是台湾的技术部落格,发现好的文章,我便会收录,今天我转载或者全文复制,在Google 博客园,一位叫保哥, 釐清 CLR..NET.C#.Visual Stu ...
随机推荐
- c#使用easyhook库进行API钩取
目标:使calc程序输入的数自动加1 (当别人使用时,总会得不到正确的结果,哈哈) 编写注入程序 ————————————————————————————————— class Program中的方法 ...
- linux终端io笔记
简介 终端的两种工作模式:以行为单位的工作模式,以字符数或时间为单位自定义模式 终端判断函数: int isatty(int fd) 终端属性的获取与设置: int tcgetattr(int fd, ...
- 菜鸟学习Struts——配置Struts环境
刚开始学习Struts,它通过采用JavaServlet/JSP技术,实现了基于Java EEWeb应用的MVC设计模式的应用框架,是MVC经典设计模式中的一个经典产品. 要用到Struts就要学会配 ...
- ERROR 1005 (HY000): Can't create table'matrix.system_log' (errno: 150)
CREATE TABLE `user` (`id` bigint(32) NOT NULL AUTO_INCREMENT ,`name` varchar(32) CHARACTER SET utf8 ...
- ThinkPHP中initialize和construct调用父类的区别
http://blog.topok.net/archives/142 需要加parent::_initialize();
- CPU原理
cpu map 1.CPU的整体架构: 2.从CPU向内存 3.CPU和内存的关系图 4.CPU指令集 5.A+B 6.结果输入寄存器 7.寄存器中的临时存储,用来暂存B 8.将B传入寄存器 9.A会 ...
- Java Day 05
数组第二种定义 数组-遍历 数组操作的核心思想就是对角标的操作: 数组-求最值 1.循环 比较 排序 选择排序 把原始数组分割成了两个数组,至少有一个是有序的 冒泡排序 相邻元素比较 位置置换代码提取 ...
- C++中使用心得
1.struct成员默认访问方式是public,而 class默认访问方式是private! 2.exit函数终止程序执行会调用析构函数 ,abort函数终止程序不会调用析构函数! 3.静态局部变量直 ...
- 自选项目--手机锁屏软件--NABC分析
N(Need 需求) 关键字:利用碎片时间加强对想记的事物的记忆.备忘.一般来说,锁屏目的大致有三点: 1.保护手机隐私 2.防止误操作手机 3.在不关闭系统软件的情况下节省电量 对于市面上已有的锁屏 ...
- asp.net中json格式化及在js中解析json
类: public class UploadDocumentItem { public UploadDocumentItem() { } public string DocMuid { get; se ...