私のプロジェクトでは、PostgreSQLと共にEntity Frameworkを使用しようとしています。しかし、私は自分のデータベースに接続できません。私は何のエラーも出ていない、それはちょうど立ち往生する。私は何かが私のapp.config
と間違っていると思うが、私は何を見つけることができない。PostgreSQLとEntity Framework
App.configファイル:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<entityFramework>
<defaultConnectionFactory type="Npgsql.NpgsqlFactory, Npgsql" />
<providers>
<provider invariantName="Npgsql"
type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" />
</providers>
</entityFramework>
<system.data>
<DbProviderFactories>
<add name="Npgsql Data Provider" invariant="Npgsql"
description="Data Provider for PostgreSQL"
type="Npgsql.NpgsqlFactory, Npgsql" />
</DbProviderFactories>
</system.data>
<connectionStrings>
<add name="Entities"
connectionString="server=localhost;user id=postgres;password=4321;database=postgis"
providerName="Npgsql" />
</connectionStrings>
</configuration>
DbContext
:
public class Entities : DbContext
{
public Entities() : base("Entities")
{
}
//rest of the code
}
mycode.cs
using (var db = new Entities()) // when debug it stuck here and keep running
{
// some test code
}
編集:私は次のエラーを取得する
:
"不変の名前「Npgsql」のADO.NETプロバイダのアプリケーション構成ファイルに登録されている「Npgsql.NpgsqlServices、Npgsql.EntityFramework」を読み込めませんでした。アセンブリに修飾された名前が使用され、アセンブリが実行中のアプリケーションで使用可能であることを確認します。
エラーはかなり明確です。プロバイダタイプの入力が間違っています。 *あなたのプロジェクトに 'Npgsql.EntityFramework.dll'という名前のアセンブリがありますか?どのパッケージのバージョンを使用しましたか? [docs](http://www.npgsql.org/doc/ef6/)のアセンブリ名は 'Npgsql.EntityFrameworkLegacy.dll'です。 –
@PanagiotisKanavos I haveEntityFramework6.Npgsqlバージョン3.1.0.0 –
@PanagiotisKanavosあなたは絶対に正しいですそれは問題だった、私は気付かなかった。あなたが答えとして私はそれを受け入れることができるあなたのコメントを置く場合。それはある人を助けるかもしれない –