Reference: #213
Visual Studio 2015 users:
Visual Studio 2013 users:
Visual Studio 2012 users:
PostgreSQL server installed:
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.
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.
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/
Notice: Recent EntityFramework6.Npgsql NuGet package automatically does this process.
<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>
You need to declare the Npgsql ADO.NET Data Provider. Edit one of following config files:
App.config
or Web.config
machine.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>
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.
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:
(by @kenjiuno)
Reference: #718
NpgsqlDdexProvider 3.0.4 and later has a feature to check Npgsql installation status of your .NET project.
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:
(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.
(by @kenjiuno)
Reference: #213
You’ll need VS2010 Professional or greater.
SP0 users:
SP1 users:
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
You’ll need VS2012 Professional or greater.
You’ll need VS2013 Professional or greater.
You’ll need VS2015 Professional or greater.
In order to debug it, you will need to use the Experimental Instance of Visual Studio.
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