Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

EF Core does not automatically add every class in your project to its model. A type is included when it is exposed through a DbSet<TEntity>, explicitly added with modelBuilder.Entity<TEntity>(), or reached through a navigation property from an included entity. First determine whether the type is missing from the EF model, present but mapped unexpectedly, or present in the model but absent from a migration; each points to a different fix.

Start by identifying what is missing

“Missing from the model” and “missing from the migration” are not the same problem. Inspect the model EF Core actually built before changing entity configuration or database schema.

  • Absent from the EF model: Check the entity’s inclusion route, any explicit exclusion, inheritance mapping, and—if the model varies intentionally—model caching.
  • Present in the model, but mapped unexpectedly: Inspect the entity’s table, properties, and configuration sources. A mapping issue does not necessarily mean discovery failed.
  • Present in the model, but absent from a migration: Check migration exclusions, the model snapshot, and the design-time context and configuration used to create the migration.

EF Core’s entity-type documentation distinguishes excluding a type from the model from excluding a mapped table from migrations. Ignore<TEntity>() and [NotMapped] exclude a type; ExcludeFromMigrations() leaves it usable in the model while stopping that context from managing the table through migrations.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check how the entity enters the model

For each missing type, check the actual DbContext used by the application or migration. Being in the same assembly—or being a plain class with properties—does not automatically make a type an entity.

  1. Look for a set on the context: Add a DbSet<Order> property if the context should expose the entity that way.
  2. Check OnModelCreating: Add modelBuilder.Entity<Order>() when you want explicit inclusion without a DbSet property.
  3. Trace navigation properties: EF Core can discover related entity types by following valid navigations from an entity already included in the model.
  4. Check for exclusions: Look for Ignore<TEntity>(), [NotMapped], or other configuration that deliberately removes the type.

These inclusion routes are described in Microsoft’s Entity Types guidance.

Do not confuse configuration scanning with entity discovery

ApplyConfigurationsFromAssembly(...) locates and applies classes implementing IEntityTypeConfiguration<TEntity>. It is a way to find configuration classes, not a general scan that registers every entity class in the assembly. Likewise, an EntityTypeConfiguration attribute is considered only after its entity type is included.

If an entity is already included but its mapping is wrong, inspect its fluent API configuration, data annotations, and configuration classes. Microsoft’s modeling documentation says fluent API configuration has the highest precedence over conventions and data annotations; when fluent calls conflict, later calls override earlier ones. That precedence explains unexpected mapping, but it does not replace the need to include an entity in the first place.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Check inheritance when the missing type is derived

If the type belongs to an inheritance hierarchy, identify its mapping strategy. With table-per-concrete-type (TPC) mapping, EF Core requires every type in the hierarchy to be included, either through DbSet properties or explicit Entity<T>() calls. Microsoft documents this behavior in its EF Core 7.0 release documentation, which also notes the difference from legacy EF6 derived-type discovery. Do not assume EF6 behavior applies to an EF Core project.

Inspect the model EF Core built

Use the model debug view described in Microsoft’s modeling guidance to examine EF Core’s metadata. Compare the actual entity types and mappings with the ones you expect. This helps distinguish an omitted type from a type that is present with an unexpected table or property configuration.

Make the inspection against the context and configuration relevant to the failing scenario. A runtime model and the model used by design-time migration tooling can differ if they are created with different contexts or configuration.

When the entity is present but the migration omits it

EF Core generates migrations by comparing the current model with the previous model snapshot; a migration is not simply a list of every entity in the application. Review the migrations overview and check these points:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
  • Is the table deliberately configured with ExcludeFromMigrations()?
  • Did the migration command use the intended context and design-time configuration?
  • Does the model snapshot represent the expected prior state?
  • Is the project using a separate migrations project, and is its design-time model configuration consistent with runtime configuration?

A separate migrations project is supported. Microsoft’s separate migrations project guidance explains the arrangement. If migrations use a different provider or design-time setup than the application, investigate that difference before concluding that runtime entity discovery is broken.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

For scaffolded contexts, keep customizations in the extension point

Database-first reverse engineering generates partial entity and context classes. The generated context calls OnModelCreatingPartial after its generated OnModelCreating configuration, giving you a place to add or override configuration without editing generated code that a later scaffold may replace. See Microsoft’s reverse-engineering documentation for the generated extension points.

Investigate model caching only when model shape varies

EF Core builds and caches a model; it does not rerun OnModelCreating for every instance of a context type. This matters when the same context type intentionally produces different model shapes based on context state. In that specialized case, the cache key must account for the state that changes the model, typically by customizing IModelCacheKeyFactory. Microsoft describes the approach in Alternating between multiple models with the same DbContext type.

Do not start here when an entity is simply unregistered. First verify its inclusion route and inspect the model; model-cache customization is relevant when a context intentionally needs multiple model shapes.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.