2016-04-01 35 views
3

Projemde, Entity Framework'ü PostgreSql ile birlikte kullanmaya çalışıyorum. Ama veritabanıma bağlanamıyorum. Hiçbir hata alamıyorum, sadece takılıp kalıyor. app.config ile ilgili bir sorun olduğunu düşünüyorum, ancak ne olduğunu öğrenemiyorum.Postgresql ve Varlık Çerçevesi

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 
} 

DÜZENLEME: aşağıdaki hatayı alıyorum

:
"'Npgsql' değişmez adıyla ADO.NET sağlayıcısı için uygulama yapılandırma dosyasında kayıtlı 'Npgsql.NpgsqlServices, Npgsql.EntityFramework' varlık çerçeve sağlayıcısı türü yüklenemedi. Derleme nitelikli adın kullanıldığından ve derlemenin çalışan uygulamaya uygun olduğundan emin olun.

+0

Hata oldukça açık. Sağlayıcı türü girişi yanlış. * Do * projenizde 'Npgsql.EntityFramework.dll' adlı bir derleme var mı? Hangi paket sürümünü kullandınız? [Docs] (http://www.npgsql.org/doc/ef6/) derleme adı 'Npgsql.EntityFrameworkLegacy.dll' –

+0

@PanagiotisKanavos I haveEntityFramework6.Npgsql sürüm 3.1.0.0 –

+0

@PanagiotisKanavos Mutlak mutlak Sorun buydu, bunu fark etmedim. Yorumunuzu cevap olarak verirseniz kabul edebilirim. birisine yardımcı olabilir –

cevap

6

Sorun, yanlış bir sağlayıcı türüne veya derleme adına işaret ediyor.

<entityFramework> 
    <defaultConnectionFactory type="Npgsql.NpgsqlFactory, Npgsql" /> 
    <providers> 
     <provider invariantName="Npgsql" 
        type="Npgsql.NpgsqlServices, Npgsql.EntityFramework" /> 
    </providers> 
</entityFramework> 

Montaj adı yanlış. EntityFramework6.Npgsql paketi tarafından kurulan derleme EntityFramework6.Npgsql.dll'dur. Aslında, paketi yeni bir projeye eklemek, doğru sağlayıcı satırını ayarlar:

<providers> 
    <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" /> 
</providers>