Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Entity Framework Core default bool issue #165

Closed
wieda opened this issue Mar 11, 2017 · 4 comments
Closed

Entity Framework Core default bool issue #165

wieda opened this issue Mar 11, 2017 · 4 comments

Comments

@wieda
Copy link

wieda commented Mar 11, 2017

When the pgsql database has a not null bool column with a default value 'true', and inserting a new record thru Npgsql.EntityFrameworkCore.PostgreSQL v. 1.1.0 with the entity value for the bool column set to 'false', the new record column value is inexplicitly set to 'true', the default value.

However, if the default value for the bool column is set to 'false', setting the entity field to 'true' does carry over into the database.

using System;
using System.Collections.Generic;

namespace PMWeb.Models
{
    public partial class Project
    {
        public Project()
        {
            ContractDocument = new HashSet<ContractDocument>();
            ProjectAddress = new HashSet<ProjectAddress>();
            ProjectOrganizationMm = new HashSet<ProjectOrganizationMm>();
            Submittal = new HashSet<Submittal>();
        }

        public long Id { get; set; }
        public DateTime CreationTime { get; set; }
        public DateTime ModifiedTime { get; set; }
        public string ProjectCode { get; set; }
        public string ProjectName { get; set; }
        public string ShortProjectName { get; set; }
        public bool Archived { get; set; }
        public string ProjectNotes { get; set; }
        public int LastSubmittalNumber { get; set; }

        public virtual ICollection<ContractDocument> ContractDocument { get; set; }
        public virtual ICollection<ProjectAddress> ProjectAddress { get; set; }
        public virtual ICollection<ProjectOrganizationMm> ProjectOrganizationMm { get; set; }
        public virtual ICollection<Submittal> Submittal { get; set; }
    }
}`

modelBuilder.Entity<Project>(entity =>
            {
                entity.ToTable("project");

                entity.HasIndex(e => e.Archived)
                    .HasName("ind_archived");

                entity.HasIndex(e => e.ProjectCode)
                    .HasName("unk_project_code")
                    .IsUnique();

                entity.HasIndex(e => e.ProjectName)
                    .HasName("unk_project_name")
                    .IsUnique();

                entity.HasIndex(e => e.ShortProjectName)
                    .HasName("unk_short_project_name")
                    .IsUnique();

                entity.Property(e => e.Id)
                    .HasColumnName("id")
                    .HasDefaultValueSql("nextval(('public.\"project_id_seq\"'::text)::regclass)");

                entity.Property(e => e.Archived)
                    .HasColumnName("archived")
                    .HasDefaultValueSql("true");

                entity.Property(e => e.CreationTime)
                    .HasColumnName("creation_time")
                    .HasDefaultValueSql("now()");

                entity.Property(e => e.LastSubmittalNumber)
                    .HasColumnName("last_submittal_number")
                    .HasDefaultValueSql("0");

                entity.Property(e => e.ModifiedTime)
                    .HasColumnName("modified_time")
                    .HasDefaultValueSql("now()");

                entity.Property(e => e.ProjectCode)
                    .IsRequired()
                    .HasColumnName("project_code")
                    .HasColumnType("varchar")
                    .HasMaxLength(10);

                entity.Property(e => e.ProjectName)
                    .IsRequired()
                    .HasColumnName("project_name")
                    .HasColumnType("varchar")
                    .HasMaxLength(120);

                entity.Property(e => e.ProjectNotes).HasColumnName("project_notes");

                entity.Property(e => e.ShortProjectName)
                    .IsRequired()
                    .HasColumnName("short_project_name")
                    .HasColumnType("varchar")
                    .HasMaxLength(20);
            });
@ianfieldarsclinica
Copy link

ianfieldarsclinica commented Aug 4, 2017

Can confirm this issue. .net core 1.1.2, Npgsql 1.1.0

Note: In our case this affects .HasDefaultValue(true)

@ajcvickers
Copy link

This looks like an EF behavior, rather than a provider-specific issue. See dotnet/efcore#7089, dotnet/efcore#7163, dotnet/efcore#9627

@iosifpetre18
Copy link

is this fixed? I have the same problem

@roji
Copy link
Member

roji commented Jun 9, 2018

Closing as this isn't Npgsql-related, see the above linked issues.

@roji roji closed this as completed Jun 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants