You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sorry for the delay have been travelling.
`
USE [Test]
GO
/****** Object: Table [dbo].[Test] Script Date: 11-Jan-19 11:37:32 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Test](
[ID] [int] NOT NULL,
[TestBool] [bit] NOT NULL,
CONSTRAINT [PK_Test] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Test] ADD CONSTRAINT [DF_Test_TestBool] DEFAULT ((1)) FOR [TestBool]
GO
`
Test.cs
`
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace EFBitTest.Model
{
[Table("Test")]
public partial class Test
{
[Column("ID")]
public int ID { get; set; }
[Required]
public bool? TestBool { get; set; }
}
}`
Our specific use case for this flag comes into play with EF Migrations. When you add a bit column to a table with existing data, you need to provide a sql default. Every time we create a new migration, we run this tool to update our POCOs, but it keeps converting our columns to nullable booleans.
Activity
ErikEJ commentedon Jan 9, 2019
Hmmm. That should have been fixed in 2.2 - can you please share a CREATE TABLE script, thanks
ErikEJ commentedon Jan 10, 2019
Ping?
mike-at-sivity-ai commentedon Jan 10, 2019
Sorry for the delay have been travelling.
`
USE [Test]
GO
/****** Object: Table [dbo].[Test] Script Date: 11-Jan-19 11:37:32 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Test](
[ID] [int] NOT NULL,
[TestBool] [bit] NOT NULL,
CONSTRAINT [PK_Test] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[Test] ADD CONSTRAINT [DF_Test_TestBool] DEFAULT ((1)) FOR [TestBool]
GO
`
Test.cs
`
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace EFBitTest.Model
{
[Table("Test")]
public partial class Test
{
[Column("ID")]
public int ID { get; set; }
[Required]
public bool? TestBool { get; set; }
}
}`
efpt.config.json
{ "ContextClassName": "TestContext", "DefaultDacpacSchema": null, "IdReplace": true, "IncludeConnectionString": true, "OutputPath": "Model", "ProjectRootNamespace": "EFBitTest", "SelectedToBeGenerated": 0, "Tables": [ { "HasPrimaryKey": true, "Name": "dbo.Test" } ], "UseDatabaseNames": false, "UseFluentApiOnly": false, "UseHandleBars": false, "UseInflector": true }bricelam commentedon Jan 10, 2019
This is by-design in EF Core. If the property wasn't nullable, there would be no way to store a
0.nullfalsetruebricelam commentedon Jan 10, 2019
Note, if you remove the
HasDefaultValueSql()configuration, you can make the property non-nullable.ErikEJ commentedon Jan 11, 2019
Closing as by design
Add option to remove default sql from non-null bit columns
Add option to remove default sql from non-null bit columns (#671)
ErikEJ commentedon Dec 18, 2020
@rationalmonkey @mike-upshon @smatvienko @rcfearn @StefanFalz @roopeshkumar
Fixed in latest daily build (two years in the making) 😄
mikerentmeister commentedon Feb 12, 2021
@ErikEJ - Would you be willing to add "Remove default constraint from bool columns" as a cli option?
ErikEJ commentedon Feb 12, 2021
To what CLI??
mikerentmeister commentedon Feb 12, 2021
@ErikEJ
We currently run this tool from the cli via the following command:
dotnet ef dbcontext scaffold
Listed here: https://github.com/ErikEJ/EFCorePowerTools/wiki/Reverse-Engineering#generate-poco-classes-derived-dbcontext-and-mapping-for-an-existing-database
mikerentmeister commentedon Feb 12, 2021
Our specific use case for this flag comes into play with EF Migrations. When you add a bit column to a table with existing data, you need to provide a sql default. Every time we create a new migration, we run this tool to update our POCOs, but it keeps converting our columns to nullable booleans.
ErikEJ commentedon Feb 12, 2021
The repository is not that tool, that tool is in the official EF Core repository.
Suggest you post the request there, feel free to refer to this issue!
mikerentmeister commentedon Feb 12, 2021
Ah, apologies, I came from the EF Core repo, but didn't realized I had switched repos.
ErikEJ commentedon Feb 12, 2021
No worries, be aware that this feature is available in EF Core Power Tools