npgsql / EntityFramework6.Npgsql

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

Default value is not generated in the database #131

Open gustavoobastos opened 5 years ago

gustavoobastos commented 5 years ago

Since version 3.1.1 the default value is not generated in the database. images for comparison: v 3.1.1: print_3_1_1

v 3.2.1.1: print_3_2_1_1

code:

using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;

namespace EntityFramework6.NpgsqlTeste
{
    public class MyContext : DbContext
    {
        public MyContext() : base("Contexto")
        {
        }

        public DbSet<Categoria> Categorias { get; set; }
    }

    [Table("Categoria")]
    public class Categoria
    {
        [Key]
        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public int IdCategoria { get; set; }

        [Required]
        public string Descricao { get; set; }

        public string Cor { get; set; }

        public int? OrdemExibicao { get; set; }

        public bool Ativo { get; set; }

        [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
        public virtual Guid IdSincronizacao { get; set; }

        [Index(IsUnique = false)]
        public int StatusSincronizacao { get; set; }

        public DateTime? DataSincronizacao { get; set; }
    }

    internal class Program
    {
        private static void Main(string[] args)
        {
            using (var ctx = new MyContext())
            {
                ctx.Database.CreateIfNotExists();
            }

            Console.ReadKey();
        }
    }
}

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>

  <system.data>
    <DbProviderFactories>
      <remove invariant="Npgsql" />
      <add name="Npgsql Data Provider" invariant="Npgsql" support="FF" description=".Net Framework Data Provider for Postgresql" type="Npgsql.NpgsqlFactory, Npgsql" />
    </DbProviderFactories>
  </system.data>

  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
  </startup>

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

  <connectionStrings>
    <add name="Contexto" providerName="Npgsql" connectionString="server=localhost;userid=postgres;password=123;database=DbTest" />
  </connectionStrings>

  <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.8.0" newVersion="4.0.8.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Threading.Tasks.Extensions" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.2.0.1" newVersion="4.2.0.1" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

</configuration>
roji commented 5 years ago

@gustavooliveirabastos thanks for reporting this. I saw you opened #129 but closed it, do you intend to try to submit a fix?