Npgsql:在Npgsql提供程序清单中找不到商店类型“jsonb”

时间:2018-06-08 12:16:52

标签: c# postgresql entity-framework entity-framework-6 npgsql

我正在尝试使用Npgsql连接到Entityframework 6的pos​​tgresql数据库。

我有'jsonb'数据类型的映射问题:

这是示例代码:

class Program
    {
        static void Main(string[] args)
        {
            using (var context = new db_Entities())
            {
                var customers = context.Customer.ToList();
                foreach (var cust in customers)
                {
                    Console.WriteLine(cust.Id);
                }

            }

            Console.ReadLine();
        }

        public partial class db_Entities : DbContext
        {
            public db_Entities() : base(nameOrConnectionString: "Default") { }

            public DbSet<Customer> Customer { get; set; }
        }

        public class Customer
        {
            [Key]
            [Column("id_customer")]
            public int id { get; set; }

            public string customer { get; set; }

            public string nit { get; set; }

            public string address { get; set; }

            [Column(TypeName = "jsonb")]
            public string SerializdJson { get; set; }
        }
    }

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" />
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
  </startup>
  <connectionStrings>
    <add name="Default" connectionString="User Id=user;Password=password;Host=localhost;Database=myDatabse;Persist Security Info=True;Search Path=test;Client Encoding=utf-8" providerName="Npgsql" />
  </connectionStrings>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
      <parameters>
        <parameter value="v13.0" />
      </parameters>
    </defaultConnectionFactory>
    <providers>
      <provider invariantName="Npgsql" type="Npgsql.NpgsqlServices, EntityFramework6.Npgsql" />
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <system.data>
    <DbProviderFactories>
      <remove invariant="Npgsql" />
      <add name="Npgsql Data Provider" invariant="Npgsql" description=".Net Data Provider for PostgreSQL" type="Npgsql.NpgsqlFactory, Npgsql, Culture=neutral, PublicKeyToken=5d8b90d52f46fda7" />
    </DbProviderFactories>
  </system.data>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Npgsql" publicKeyToken="5d8b90d52f46fda7" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
</configuration>

packages.config:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="EntityFramework" version="6.2.0" targetFramework="net461" />
  <package id="EntityFramework6.Npgsql" version="3.1.1" targetFramework="net461" />
  <package id="Npgsql" version="4.0.0" targetFramework="net461" />
  <package id="System.Runtime.CompilerServices.Unsafe" version="4.5.0" targetFramework="net461" />
  <package id="System.Threading.Tasks.Extensions" version="4.5.0" targetFramework="net461" />
  <package id="System.ValueTuple" version="4.5.0" targetFramework="net461" />
</packages>

当我执行此程序时,我收到此错误

The store type 'jsonb' could not be found in the Npgsql provider manifest

如果我删除属性[Column(TypeName = "jsonb")],程序可以正常工作

有什么遗失吗?

0 个答案:

没有答案