Skip to content

Scaffolding with NRT generates non-nullable navigation property from principal to dependent #27496

@roji

Description

@roji

Scaffolding the following schema in a project with NRT enabled:

CREATE TABLE Principal
(
    Id INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
);

CREATE TABLE Dependent
(
    Id INT IDENTITY(1,1) NOT NULL PRIMARY KEY,
    PrincipalId INT NOT NULL,
    CONSTRAINT FK_A_B FOREIGN KEY (PrincipalId) REFERENCES [Principal](Id)
);

CREATE UNIQUE NONCLUSTERED INDEX [IX_Dependent_PrincipalId] ON [Dependent] ([PrincipalId] ASC);

... generates the following CLR type for Principal:

public partial class Principal
{
    public int Id { get; set; }

    public virtual Dependent Dependent { get; set; } = null!;
}

The Dependent navigation property should be nullable.

Raised by @AFract in ErikEJ/EFCorePowerTools#1298

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions