Skip to content

Instantly share code, notes, and snippets.

@ajai8085
Created October 18, 2017 22:46
Show Gist options
  • Save ajai8085/1d64452995534c3317d8aeb48929e25d to your computer and use it in GitHub Desktop.
Save ajai8085/1d64452995534c3317d8aeb48929e25d to your computer and use it in GitHub Desktop.
npsql connection string

https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/obtaining-a-dbproviderfactory

Provider factory make available globally for non .net core / no nuget way

read here : http://www.npgsql.org/doc/connection-string-parameters.html

Installing npsql to GAC is required in order to run pocogenerator for described here https://github.com/MoonStorm/Dapper.FastCRUD/wiki/Entity-registration#autot4

However, this tool will still not work for postgress sql because there is no SchemaReader implementation for postgress in GenericModelGenerator.tt. This tool only work for sql server

#Workaround . Use npsql's poco generator , works well with .net core 2.0

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7"/>
</DbProviderFactories>
</system.data>
<connectionStrings >
<add name="default" connectionString="User ID=postgres;Password=Password_ChangeIt;Host=localhost;Port=5432;Database=sampledb;" providerName="Npgsql" />
</connectionStrings>
</configuration>
using System.Data;
public struct Program(){
public static void Main(){
//https://docs.microsoft.com/en-us/dotnet/framework/data/adonet/obtaining-a-dbproviderfactory
var table = GetProviderFactoryClasses();
var factory=DbProviderFactories.GetFactory("Npgsql");
}
static DataTable GetProviderFactoryClasses()
{
// Retrieve the installed providers and factories.
DataTable table = DbProviderFactories.GetFactoryClasses();
// Display each row and column value.
foreach(DataRow row in table.Rows)
{
foreach(DataColumn column in table.Columns)
{
Console.WriteLine(row[column]);
}
}
return table;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment