ErikEJ / EFCorePowerTools

Entity Framework Core Power Tools - reverse engineering, migrations and model visualization in Visual Studio & CLI
MIT License
2.18k stars 298 forks source link

ISSUE: Remove SQL default from bool columns does not seem to work #2601

Open chassq opened 13 hours ago

chassq commented 13 hours ago

This is a follow-up issue based on a question asked in: https://github.com/ErikEJ/EFCorePowerTools/pull/2478

When we have a column is a database table for example:

[IsActive] BIT NOT NULL CONSTRAINT [DF_dbo_MyTable_IsActive] DEFAULT ((1))

The model is being set to

public bool IsActive { get; set; }

where is used to be

public bool? IsActive { get; set; }

regardless of if the Remove SQL default from bool columns is checked or not.

We believe this has changed since the last version. The issue it creates is now when we new up a model the IsActive C# default value of false is used and causes the value in the db to be set to false instead of the true the system intends.

Provide technical details

- VISUAL STUDIO DETAIL: Microsoft Visual Studio Enterprise 2022 Version 17.12.0 Preview 5.0 VisualStudio.17.Preview/17.12.0-pre.5.0+35424.110 Microsoft .NET Framework Version 4.8.09032

Installed Version: Enterprise

Visual C++ 2022 00476-80000-00000-AA584 Microsoft Visual C++ 2022

ADL Tools Service Provider 1.0 This package contains services used by Data Lake tools

ASA Service Provider 1.0

ASP.NET and Web Tools 17.12.174.40113 ASP.NET and Web Tools

Azure App Service Tools v3.0.0 17.12.174.40113 Azure App Service Tools v3.0.0

Azure Data Lake Tools for Visual Studio 2.6.5000.0 Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools 17.12.174.40113 Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio 2.6.5000.0 Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools 4.12.0-3.24510.2+3fd39c8f6c8db918e3184050599c2046997160f1 C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Entity Framework Core Power Tools 2.6 Adds useful design-time EF Core DbContext features to the Visual Studio Solution Explorer context menu.

Extensibility Message Bus 1.4.42 (main@840f8b3) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration.

GitHub Copilot 17.12.27.11192 GitHub Copilot is an AI pair programmer that helps you write code faster and with less work.

Markdown Editor v2 2.0.169 A full featured Markdown editor with live preview and syntax highlighting. Supports GitHub flavored Markdown.

Microsoft Azure Hive Query Language Service 2.6.5000.0 Language service for Hive query

Microsoft Azure Stream Analytics Language Service 2.6.5000.0 Language service for Azure Stream Analytics

Microsoft Azure Tools for Visual Studio 2.9 Support for Azure Cloud Services projects

Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

Mono Debugging for Visual Studio 17.12.5 (918dbb1) Support for debugging Mono processes with Visual Studio.

NuGet Package Manager 6.12.0 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

PowerShell Pro Tools for Visual Studio 1.0 A set of tools for developing and debugging PowerShell scripts and modules in Visual Studio.

Razor (ASP.NET Core) 17.12.3.2451803+13fe97052e82683ec4c9fc916531eba5c751037f Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools 17.12.78.0 Microsoft SQL Server Data Tools

Test Adapter for Boost.Test 1.0 Enables Visual Studio's testing tools with unit tests written for Boost.Test. The use terms and Third Party Notices are available in the extension installation directory.

Test Adapter for Google Test 1.0 Enables Visual Studio's testing tools with unit tests written for Google Test. The use terms and Third Party Notices are available in the extension installation directory.

ToolWindowHostedEditor 1.0 Hosting json editor into a tool window

TypeScript Tools 17.0.30918.2001 TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools 4.12.0-3.24510.2+3fd39c8f6c8db918e3184050599c2046997160f1 Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools 17.12.0-beta.24501.1+19610c0b654766eec49d044cb97ca6eaa2a63d16 Microsoft Visual F# Tools

Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio.

VisualStudio.DeviceLog 1.0 Information about my package

VisualStudio.Mac 1.0 Mac Extension for Visual Studio

VSPackage Extension 1.0 VSPackage Visual Studio Extension Detailed Info

Xamarin 17.12.0.152 (d17-12@c9ed1ee) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.

Xamarin Designer 17.12.3.17 (remotes/origin/main@0912a005b9) Visual Studio extension to enable Xamarin Designer tools in Visual Studio.

Xamarin.Android SDK 13.2.2.0 (d17-5/45b0e14) Xamarin.Android Reference Assemblies and MSBuild support. Mono: d9a6e87 Java.Interop: xamarin/java.interop/d17-5@149d70fe SQLite: xamarin/sqlite/3.40.1@68c69d8 Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d

ErikEJ commented 12 hours ago

What mapping is generated?

ErikEJ commented 12 hours ago

What happens if you reverse engineer from a live database?

chassq commented 11 hours ago

The old configuration was:

entity.Property(e => e.IsActive)
    .IsRequired()
    .HasDefaultValueSql("1");

The new one is: entity.Property(e => e.IsActive).HasDefaultValue(true);

We get the same thing from a live database.

ErikEJ commented 11 hours ago

Can you share a console app that demonstrates the issue?

ErikEJ commented 11 hours ago

Related EF Core issue: https://github.com/dotnet/efcore/issues/33683

ErikEJ commented 10 hours ago

Description of the breaking chnage in EF Core 8 and mitigations: https://learn.microsoft.com/en-us/ef/core/what-is-new/ef-core-8.0/breaking-changes#scaffold-bools