实体框架6 Npgsql [英] Entity Framework 6 with Npgsql

查看:902
本文介绍了实体框架6 Npgsql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在ASP.NET MVC 4项目使用实体框架6 PostgreSQL的。我有实体框架6.0.2 + Npgsql 2.0.14.3,但我得到的错误。我该如何解决这个问题?

错误:


  

'System.InvalidOperationException'类型的异常出现在mscorlib.dll但在用户code没有处理


  
  

其他信息:实体框架提供程序类型的实例成员Npgsql.NpgsqlServices,Npgsql,版本= 2.0.14.3,文化=中性公钥= 5d8b90d52f46fda7未返回从System.Data这继承对象.Entity.Core.Common.DbProviderServices。实体框架供应商必须从该类继承和实例成员必须返回供应商的单一实例。这可能是因为供应商不支持实体框架6或更高版本;看<一个href=\"http://go.microsoft.com/fwlink/?LinkId=260882\">http://go.microsoft.com/fwlink/?LinkId=260882了解更多信息。


Web.config文件

 &LT;&System.Data这GT;
  &LT; D​​bProviderFactories&GT;
    &LT;添加名称=Npgsql数据提供程序
        不变=Npgsql
        说明=PostgreSQL的数据提供程序
        键入=Npgsql.NpgsqlFactory,Npgsql/&GT;
  &LT; / DbProviderFactories&GT;
&LT; /system.data>
&LT;&是connectionStrings GT;
  &LT;添加名称=DatabaseContext的connectionString =服务器=本地主机,端口= 5432;数据库=为主;用户ID = Postgres的;密码=密码;的providerName =Npgsql/&GT;
&LT; /&是connectionStrings GT;
&LT;&的EntityFramework GT;
  &LT;供应商&GT;
    &LT;供应商invariantName =NpgsqlTYPE =Npgsql.NpgsqlServices,Npgsql/&GT;
  &LT; /供应商&GT;
&LT; /&的EntityFramework GT;


解决方案

我需要安装Npgsql是这样的:

安装封装Npgsql.EF6 - pre

它安装不同版本,它的工作原理。

更新:
我发现,新的测试版你可以写

安装包Npgsql.EntityFramework - pre

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>

解决方案

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

这篇关于实体框架6 Npgsql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆