npgsql / efcore.pg

Entity Framework Core provider for PostgreSQL
PostgreSQL License
1.53k stars 223 forks source link

Provider-specific date/time types (e.g. NpgsqlDate) not supported in 2.1.0 #467

Open iflight opened 6 years ago

iflight commented 6 years ago

After update to net core 2.1 and Npgsql.EntityFrameworkCore.PostgreSQL 2.1, EF throw exception:

System.InvalidOperationException: "The property 'TBReestr.TBrDateEnd' is of type 'Nullable\<NpgsqlDate>' which is not supported by current database provider.

And same problem with Nullable\<NpgsqlDateTime>.

part of Model:

    public class TBReestr
    {
        public long TBrId { get; set; }
        public NpgsqlDate? TBrDateStart { get; set; }
        public NpgsqlDate? TBrDateEnd { get; set; }
 }

modelBuilder:

     modelBuilder.Entity<TBReestr>(entity =>
            {
                entity.HasKey(e => e.TBrId);

                entity.ToTable("tBReestr");

                entity.Property(e => e.TBrDateStart)
                    .HasColumnName("tBR_DateStart");

                entity.Property(e => e.TBrDateEnd)
                    .HasColumnName("tBR_DateEnd");
}

Connection:

services.AddEntityFrameworkNpgsql().AddDbContextPool<DataContext>(options => options.UseNpgsql(configuration.GetConnectionString("DataConnection")));

Npgsql version: 4.0 Npgsql.EntityFrameworkCore.PostgreSQL 2.1 net core 2.1 PostgreSQL version: 9.6.6 Operating system: Win10

iflight commented 6 years ago

Why I use NpgsqlDate\NpgsqlDateTime instead of DateTime? We use (+-)Infinity values of timestamp in postgres base (Default values for some data in db). DateTime doesn't support it (maybe infinity must be mapped to DateTime.Max/.Min values, now i convert it in code). Migrate to NodaTime not easy when you has a lot of code with manipulating DateTime. p.s. Sorry for my English :(

roji commented 6 years ago

You can specify Convert Infinity DateTime=true to access infinity values as DateTime.{Max,Min}Value, this allows you to avoid using the Npgsql-interactive specific types which are frankly not that great.

roji commented 6 years ago

Moving to backlog as there's not much request for this, and we're considering deprecating the provider-specific date/time types altogether (https://github.com/npgsql/npgsql/issues/2009).