Halloween DealsAmazon USHalloween week deals: useful picks before month-endAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix NowHalloween DealsAmazon USOctober picks are moving - compare before checkoutAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

When EF Core Sees Only Part of Your Model: How to Diagnose Missing Entities

EF Core includes entities through DbSet properties, explicit registration, or navigations—not simply because a class exists. Learn how to tell a missing model entity from a migration omission or unexpected mapping.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

EF Core does not automatically add every class in your project to its model. An entity generally enters through a DbSet<TEntity> property, an explicit modelBuilder.Entity<TEntity>() call, or a navigation property from an entity already included. If something appears to be missing, first determine whether it is absent from the EF model, present but mapped unexpectedly, or present in the model but omitted from a migration. Each points to a different fix.

First identify what is missing

“EF Core is not detecting my entity” can describe three different problems. Inspect the model EF actually built before changing mappings or generating another migration.

As an Amazon Associate I earn from qualifying purchases.

  • Absent from the model: EF has no entity metadata for the type. Check its inclusion route and whether it was explicitly excluded.
  • Present, but mapped unexpectedly: The entity exists in the model, but its table, properties, or relationships do not match your expectations. Review conventions, attributes, and Fluent API configuration.
  • Present in the model, absent from migration operations: Migration output is not a complete list of model entities. The table may be excluded from migrations, or the migration may have no schema change to apply.

EF Core documents entity inclusion and migration exclusions separately in Entity Types and its Migrations Overview.

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

Check how EF Core includes the type

A class being public, located beside other entities, or compiled into the same assembly does not by itself add it to the model. For each missing type, verify that the context actually in use includes it through one of the documented routes:

  • A DbSet<TEntity> property on that context.
  • An explicit modelBuilder.Entity<TEntity>() call in its OnModelCreating method.
  • A valid navigation property from an entity that is already included; EF recursively discovers related types through navigation properties.

For example, explicit registration can look like this:

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

Use the context your application or migration tooling really constructs. Registering an entity in a different context will not add it to the model being inspected.

Do not confuse configuration scanning with entity discovery

ApplyConfigurationsFromAssembly(...) finds and applies implementations of IEntityTypeConfiguration<TEntity>. That is a way to apply mapping configuration; it is not a general scan that adds every class in the assembly as an entity.

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

Likewise, an EntityTypeConfiguration attribute does not independently cause EF Core to discover its entity type. The type must first be included in the model. See Creating and Configuring a Model for configuration methods and their precedence.

Check exclusions and inheritance

Look for explicit exclusion

modelBuilder.Ignore<TEntity>() and the [NotMapped] attribute exclude a type from the model. Remove or revise the exclusion if the type should be modeled.

Do not mistake ExcludeFromMigrations() for an entity exclusion. It leaves the entity in the EF model while telling migrations not to manage that mapped table. That setting is appropriate when the context uses a table but another process or context owns its schema.

For TPC, include every type in the hierarchy

If the missing type is part of an inheritance hierarchy mapped with table-per-concrete-type (TPC), explicitly include every type in that hierarchy, using DbSet properties or Entity<T>() calls as appropriate. EF Core 7 documentation notes that this differs from the derived-type discovery behavior associated with legacy EF6; do not assume EF6 rules apply. See What’s New in EF Core 7.0.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

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

Inspect the model before changing the database

EF Core’s model debug view lets you examine the metadata it built. Compare that view with your intended entities and mappings: it can show whether a type is absent or present with a different configuration. The modeling documentation describes the debug view and configuration behavior.

When the type is present but mapped differently, consider configuration precedence. Fluent API configuration in OnModelCreating takes precedence over data annotations and conventions. If multiple Fluent API calls conflict, later calls override earlier ones. An unexpected mapping can therefore result from an override rather than failed discovery.

Compare the runtime model with migration output

EF Core generates migrations by comparing the current model with the previous model snapshot. A migration records schema changes relative to that snapshot; it is not an inventory of every entity. If an entity is in the model but a migration has no operation for it, check the table’s migration-exclusion setting and whether the snapshot and current model actually differ.

Also verify that design-time tooling used the intended context and configuration. A separate migrations project is supported, but its provider and design-time model configuration should be consistent with runtime configuration. See Using a Separate Migrations Project.

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

Use the right extension point for scaffolded contexts

Database-first reverse engineering generates partial entity and context classes. The generated context calls OnModelCreatingPartial after its generated OnModelCreating configuration. Put durable additions or overrides in the partial extension point rather than editing generated files that a later scaffold may overwrite. The Reverse Engineering documentation explains these extension points.

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

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 model cache key must distinguish the variants, typically through IModelCacheKeyFactory. See Alternating between multiple models with the same DbContext type.

For an ordinary missing entity, check inclusion and exclusions first. Model-cache customization is relevant only when the model is deliberately supposed to vary for the same context type.

A practical diagnostic order

  1. Inspect the built model. Decide whether the entity is absent or present with unexpected mapping.
  2. Verify the context. Check that the application or design-time tooling is using the context you changed.
  3. Trace inclusion. Look for a DbSet, explicit registration, or a navigation from an included entity.
  4. Review exclusions and inheritance. Check Ignore, [NotMapped], migration exclusions, and—in TPC hierarchies—explicit inclusion of every type.
  5. If only a migration is missing, inspect the snapshot and design-time setup. Confirm the model difference and that migration configuration matches the intended context.
  6. If the context is scaffolded, use its partial extension point. If the model intentionally varies by context state, then investigate cache-key customization.

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.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

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

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.