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

RevEng: bool property with default is marked as nullable even if it is non-nullable in database #10305

Closed
smitpatel opened this issue Nov 15, 2017 · 3 comments
Assignees
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Milestone

Comments

@smitpatel
Copy link
Member

Model

    public class Blog
    {
        public int Id { get; set; }
        public bool? Value { get; set; }
    }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            // Configure model
            var property = modelBuilder.Entity<Blog>().Property(e => e.Value);
            property.HasDefaultValue(true);
            property.IsRequired(true);

        }

Generated this table

      CREATE TABLE [Blogs] (
          [Id] int NOT NULL IDENTITY,
          [Value] bit NOT NULL DEFAULT 1,
          CONSTRAINT [PK_Blogs] PRIMARY KEY ([Id])
      );

Which reverse engineered this model

    public partial class Blogs
    {
        public int Id { get; set; }
        public bool? Value { get; set; }
    }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.Entity<Blogs>(entity =>
            {
                entity.Property(e => e.Value).HasDefaultValueSql("((1))");
            });
        }

We are incorrectly making the property nullable even though it is not.

smitpatel added a commit that referenced this issue Nov 15, 2017
… made nullable if the column is already nullable

Also we marked required column as nullable when we derived nullable clr type

Resolves #10144
Resolves #10305
@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Nov 15, 2017
@smitpatel smitpatel self-assigned this Nov 15, 2017
smitpatel added a commit that referenced this issue Nov 15, 2017
… made nullable if the column is already nullable

Also we marked required column as nullable when we derived nullable clr type

Resolves #10144
Resolves #10305
@smitpatel smitpatel reopened this Nov 15, 2017
@ajcvickers ajcvickers added this to the 2.1.0 milestone Nov 17, 2017
@alextof
Copy link

alextof commented May 9, 2019

It happens again with .NET Core 2.2.102, latest EF Core Power Tools & Azure SQL Database performing reverse engineering with Power Tools.

@sgxman
Copy link

sgxman commented May 13, 2019

It happens again with .NET Core 2.2.102, latest EF Core Power Tools & Azure SQL Database performing reverse engineering with Power Tools.

I also have this exact problem.
In SQL-Server: Bit column, NOT NULL, Default Value ((1))
Class gets generated as: public bool?

/Jonny

My Environment

Visual Studio 2017 (all updates)
SQL Server 2014 SP1
EF Core Power Tools - 2.2.12
EF Core 2.1.8
NET Core 2.2.102

@ajcvickers
Copy link
Member

@alextof @sgxman This is by-design when the default value in the column is not the same as the CLR default for the type. Once #15182 is implemented, we may generate something different.

@ajcvickers ajcvickers modified the milestones: 2.1.0-preview1, 2.1.0 Nov 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. type-bug
Projects
None yet
Development

No branches or pull requests

4 participants