npgsql / EntityFramework6.Npgsql

Entity Framework 6 provider for PostgreSQL
PostgreSQL License
66 stars 53 forks source link

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

Open mouadhtrabelsi opened 6 years ago

mouadhtrabelsi commented 6 years ago

I m trying to use Npgsql to connect to postgresql database with Entityframework 6.

I have a mapping problem with 'jsonb' data type :

this is sample code :

    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; }
            }
        }

The 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>

the 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>

when i execute this program i get this error

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

if i remove the attribute [Column(TypeName = "jsonb")] the program work fine

Is there something missing ?

afriedma commented 6 years ago

I have the same issue, do you have a temporary work around?

I am following your sample on http://www.npgsql.org/ef6/

mouadhtrabelsi commented 6 years ago

@afriedma no, i did not found any workaround i was testing Npgsql to migrate from Devart to use Npgsql instead but i faced a lot of problems ... so i will continue to use devart for now , as Npgsql is not stable yet to use it with EF6