While using a PostgreSQL database with Entity Framework on Mono using the packages Npsql and Npsql.EntityFramework I get an exception while trying to run Code First migratio
It was not necessary to disable MARS. What can be seen from the explicit stack trace is that my context used a default connection string. This happened because I was running migrations from a separate project in a console app.
When I copied some of the information in the web.config
of the default project (where the DbContext
resided) to the app.config
of the console app the builder compiled.
The migrations are working (!) and the MARS error does not happen any more since the correct connection string is now taken.
Duplicated xml-configuration in app.config
of migrations project:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.1.1, Culture=neutral, PublicKeyToken=b77a5c561934e089"
requirePermission="false" />
</configSections>
<!-- <connectionStrings configSource="../Zk/ConnectionStrings.config" /> -->
<connectionStrings>
<clear />
<add name="ZkTestDatabaseConnection"
connectionString="Server=localhost;Port=5432;Database=ZkTestDatabase;User Id=zktest;Password=broccoli;CommandTimeout=20;"
providerName="Npgsql" />
</connectionStrings>
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider"
invariant="Npgsql"
description="Data Provider for PostgreSQL"
type="Npgsql.NpgsqlFactory, Npgsql" />
</DbProviderFactories>
</system.data>
<entityFramework>
<defaultConnectionFactory type="Npgsql.NpgsqlFactory, Npgsql" />
<providers>
<provider invariantName="Npgsql"
type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
</providers>
</entityFramework>
</configuration>