PostgreSQL 9.5 Npgsql 3.1.9
I have been using PetaPoco with Npgsql to generate the POCO's with the Database.tt. All has worked well until today. After remaking the schema's in PostgreSQL, now running the Database.tt gives the error:
// This file was automatically generated by the PetaPoco T4 Template
// Do not make changes directly to this file - edit the template instead
// The following connection settings were used to generate this file
// Connection String Name:
localconnection
// Provider:
Npgsql
// Connection String:
Server=127.0.0.1;Port=5432;Database=chaos;User Id=postgres;password=**zapped**;Searchpath=nova
// Schema: ``
// Include Views:
False
//
// Failed to read database schema - Sequence contains more than one matching element
I could find nothing in Google that address: What does this mean (for PetaPoco), why did it happen, and how do I fix it?
TIA
Edit#1: If it helps any, in stepping through the T4 template, the _factory type resolves to SQL Server CE --not NpgsqlFactory -- despite having the correct connection string.
_factory.GetType().Name == "SqlCeProviderFactory"
Edit#2: By rewriting LoadTables() in PetaPoco.Core.ttinclude by placing the
else if (_factory.GetType().Name == "NpgsqlFactory")
Edit#3: Now went back to PetaPoco v 5.1.211, still the same error???
The problem appears to be in LoadTables() which for Npgsql will load every table of every schema initially--even though a specific schema is listed in the searchpath, but then (why?) it zeroes out the table count before generating the tables.
Can anybody help with this??
Npgsql was installed from Nuget, as was PetaPoco.
For reference, all worked great before recreating and renaming the schemas.
The app.config
is:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2"/>
</startup>
<system.data>
<DbProviderFactories>
<remove invariant="Npgsql" />
<add name="Npgsql Data Provider" invariant="Npgsql" support="FF"
description=".Net Framework Data Provider for Postgresql Server"
type="Npgsql.NpgsqlFactory, Npgsql" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<clear/>
<add name="localconnection" providerName="Npgsql"
connectionString="Server=127.0.0.1;Port=5432;Database=chaos;User Id=postgres;Password=password;Searchpath=nova"/>
</connectionStrings>
The Database.tt
is set up with:
// Settings
ConnectionStringName = "localconnection"; // Uses last connection string in config if not specified
Namespace = "chaos";
RepoName = "chaosDB";
GenerateOperations = true;
GeneratePocos = true;
GenerateCommon = true;
ClassPrefix = "";
ClassSuffix = "";
TrackModifiedColumns = false;
ExplicitColumns = true;
ExcludePrefix = new string[] {}; // Exclude tables by prefix.
This is what worked, but points out some inherent problem with LoadTables() as it applies to Npgsql when the PostgreSQL database has multiple schemas--I'm guessing a name conflict somewhere..
I went back to my PostgreSQL database and dropped every schema except the one I needed. Now running the Database.tt template correctly and quickly produced the POCO's without error.
Additionally, the previous version of PetaPoco had no problem with multiple schemas--its the newest version that seems to have difficulties.