-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Why does my non-nullable navigation property have a nullable backing field? #23588
Labels
area-model-building
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-bug
Milestone
Comments
Note for triage: I am able to reproduce this. #nullable enable
public class Blog
{
public int Id { get; set; }
public string Name { get; set; }
}
public class Post
{
public int Id { get; set; }
public string Content { get; set; }
public Blog Blog { get; set; }
}
public class SomeDbContext : DbContext
{
private static ILoggerFactory ContextLoggerFactory
=> LoggerFactory.Create(b => b.AddConsole().SetMinimumLevel(LogLevel.Information));
public DbSet<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseSqlServer(Your.ConnectionString)
.UseLoggerFactory(ContextLoggerFactory)
.EnableSensitiveDataLogging();
}
public class Program
{
public static void Main()
{
using (var context = new SomeDbContext())
{
context.Database.EnsureDeleted();
context.Database.EnsureCreated();
}
}
} CREATE TABLE [Blogs] (
[Id] int NOT NULL IDENTITY,
[Name] nvarchar(max) NOT NULL,
CONSTRAINT [PK_Blogs] PRIMARY KEY ([Id])
);
CREATE TABLE [Posts] (
[Id] int NOT NULL IDENTITY,
[Content] nvarchar(max) NOT NULL,
[BlogId] int NULL,
CONSTRAINT [PK_Posts] PRIMARY KEY ([Id]),
CONSTRAINT [FK_Posts_Blogs_BlogId] FOREIGN KEY ([BlogId]) REFERENCES [Blogs] ([Id]) ON DELETE NO ACTION
); |
Notes for triage:
|
ajcvickers
added
area-model-building
customer-reported
type-enhancement
type-bug
and removed
type-enhancement
labels
Dec 4, 2020
AndriySvyryd
added
the
verify-fixed
This issue is likely fixed in new query pipeline.
label
Aug 31, 2021
AndriySvyryd
added a commit
that referenced
this issue
Sep 1, 2021
AndriySvyryd
added
the
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
label
Sep 1, 2021
AndriySvyryd
added a commit
that referenced
this issue
Sep 2, 2021
AndriySvyryd
removed
the
verify-fixed
This issue is likely fixed in new query pipeline.
label
Sep 29, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area-model-building
closed-fixed
The issue has been fixed and is/will be included in the release indicated by the issue milestone.
customer-reported
type-bug
I created the following class:
but the backing field in the database is
BlogId (FK, int, null)
instead ofnot null
. I have enabled nullable reference type in my project. Is there anything else I should configure?Thank you.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
The text was updated successfully, but these errors were encountered: