C#アプリケーションでEntity Framework Code-Firstを使用してPostgreSQLサーバにデータベースを作成しようとしています。私はEFのためのNpgsqlをダウンロードし、インターネット上で提示された様々な方法で私のApp.configファイルを変更しようとしましたが、何も動作しません。EntityFramework 6(C#)を使用してPostgreSQLデータベースに接続
これは私のApp.configファイルである:私はそのSqlServer
作品を追加したいと思い
<?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.2" />
</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>
<connectionStrings>
<add name="SqlServer" connectionString="Data Source=localhost;Initial Catalog=MyDB;Integrated Security=true" providerName="System.Data.SqlClient" />
<add name="PostgreSql" connectionString="Data Source=localhost;Initial Catalog=MyDB;Integrated Security=true;User Id=postgre;Password=password;" providerName="Npgsql" />
</connectionStrings>
</configuration>
。私は助けに感謝します。
アプリケーションに両方のプロバイダが必要な場合は、どちらを使用するかをEFに伝える必要があります。それ以外の場合は、SqlServerエントリを削除し、デフォルトの接続ファクトリをNpgsqlが提供するものに変更します。 – Spivonious
Contextクラスのコンストラクタでbase( "PostgreSql")を使用しています。どのようにデフォルトの外観にする必要がありますか? – Niko
それで十分でしょう。コンテキストを使用する際にエラーが発生していますか? – Spivonious