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

Add-Migration generates nullable columns for non-nullable properties inside owned types #18785

Closed
RafaelSalguero opened this issue Nov 6, 2019 · 1 comment

Comments

@RafaelSalguero
Copy link

Migration tool Add-Migration generates code for adding a nullable column for non-nullable properties inside owned types

Steps to reproduce

1.- C# 8 nullable checks are on
2.- Add a non-nullable property to an Owned type
3.- Run Add-Migration
4.- nullable: true code is generated

class MyEntity {
  [Key]
  public int Id { get; set; }

  //This property is correctly generated (non nullable)
  public bool MyProp { get; set; }

  public MyOwnedType OwnedType { get; set; } = new MyOwnedType();
}

[Owned]
class MyOwnedType {
  //This property is generated as a nullable column (wrong)
  public bool OwnedProp { get; set; }
}

Generated code:

 
          migrationBuilder.AddColumn<bool>(
                name: "MyProp",
                table: "MyEntity",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddColumn<bool>(
                name: "OwnedType_OwnedProp",
                table: "MyEntity",
                nullable: true);

Further technical details

EF Core version: 3.0.0
Database provider: Microsoft.EntityFrameworkCore.SqlServer 3.0.0
Target framework: netcoreapp3
Operating system: Windows 10
Visual Studio 2019 16.3.7

@ajcvickers
Copy link
Contributor

Duplicate of #16943

@ajcvickers ajcvickers marked this as a duplicate of #16943 Nov 6, 2019
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants