Wpis z mikrobloga

Patrzę sobie na ten prosty przykład z EF Core MS Docs:
https://docs.microsoft.com/en-us/ef/core/modeling/entity-types?tabs=fluent-api

I nie rozumiem dlaczego nie ma DbSet dla postów:

internal class MyContext : DbContext
{
public DbSet Blogs { get; set; }

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity();
}
}

Wiecie czemu tak jest?

#naukaprogramowania #csharp #efcore #pytanie #pytaniedoeksperta #entityframeworkcore
  • 6
  • Odpowiedz
@vanguard2727: Blog ma posty w sobie. Cytując. …OnModelCreating method are also included, as are any types that are found by recursively exploring the navigation properties of other discovered entity types.
  • Odpowiedz
Czyli jeśli coś nie może żyć "samo z siebie", to nie dodaje się tego do DbSet, tak?


@vanguard2727: Gdybyś miał potrzebę np. pobierania posta po id to warto by dodać taki DbSet. Tutaj nie było takiej potrzeby ale jeśli chcesz to lajtowo możesz sobie takie coś dodać.
  • Odpowiedz