KEMBAR78
NullReferenceException when trying to seed a keyless entity · Issue #23030 · dotnet/efcore · GitHub
Skip to content

NullReferenceException when trying to seed a keyless entity #23030

@roji

Description

@roji

Repro:

await using var ctx = new BlogContext();
await ctx.Database.EnsureDeletedAsync();
await ctx.Database.EnsureCreatedAsync();

public class BlogContext : DbContext
{
    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        => optionsBuilder.UseSqlServer(...);

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<Blog>()
            .HasNoKey()
            .HasData(new Blog { Name = "foo" });
    }
}

public class Blog
{
    public string Name { get; set; }
}

Happens on both the latest 5.0 and 3.1.

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions