Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
416 views
in Technique[技术] by (71.8m points)

c# - Entity Framework 6 with Npgsql

I want to use Entity Framework 6 with PostgreSQL in ASP.NET MVC 4 project. I got Entity Framework 6.0.2 + Npgsql 2.0.14.3, but I get error. How do I fix this?

Error:

An exception of type 'System.InvalidOperationException' occurred in mscorlib.dll but was not handled in user code

Additional information: The 'Instance' member of the Entity Framework provider type 'Npgsql.NpgsqlServices, Npgsql, Version=2.0.14.3, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7' did not return an object that inherits from 'System.Data.Entity.Core.Common.DbProviderServices'. Entity Framework providers must inherit from this class and the 'Instance' member must return the singleton instance of the provider. This may be because the provider does not support Entity Framework 6 or later; see http://go.microsoft.com/fwlink/?LinkId=260882 for more information.

Web.config

<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="DatabaseContext" connectionString="Server=localhost;port=5432;Database=main;User Id=postgres;Password=password;" providerName="Npgsql" />
</connectionStrings>
<entityFramework>
  <providers>
    <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, Npgsql" />
  </providers>
</entityFramework>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I needed to install Npgsql like this:

Install-Package Npgsql.EF6 -Pre

It installs different version which works.

UPDATE: I found that for newer beta version you can write

install-package Npgsql.EntityFramework -pre


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...