C# Entity Framework Basics Extending Our Entity Data Model Using a One-to-Many Relationship

Why don't we need to add dbset property for Series in the context class?

How the entity framework create a table for Series when we don't add dbset property for it in context class?

There's a question about it before, but I don't understand the answer.

https://teamtreehouse.com/community/why-are-we-not-creating-a-dbset-property-of-type-series-in-the-context-class-entity-framework

1 Answer

Steven Parker
Steven Parker
171,227 Points

Table creation is discussed in the Where's Our Data? video starting at about 4:00.

In short, the DbSet entries are examined for entity relationships, using the models. The models are then used to create the conceptual model, which is then translated into the storage model. The storage model is used to create the actual tables.

The Series entity doesn't have a DbSet, but it has a one-to-many relationship with ComicBook, which causes it to be included in the conceptual model and storage model, and then to be created as a table.