{"record":{"id":"6b180703cb732ed6","repo":"dotnet/efcore","slug":"the-entity-type-entitytype-was-not-found-ensu","errorCode":null,"errorMessage":"The entity type '{entityType}' was not found. Ensure that the entity type has been added to the model.","messagePattern":"The entity type '(.+?)' was not found\\. Ensure that the entity type has been added to the model\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Proxies/Proxies/Internal/ProxyFactory.cs","lineNumber":45,"sourceCode":"    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public virtual object Create(\n        DbContext context,\n        Type type,\n        params object[] constructorArguments)\n    {\n        var entityType = context.Model.FindRuntimeEntityType(type);\n        if (entityType == null)\n        {\n            if (context.Model.IsShared(type))\n            {\n                throw new InvalidOperationException(ProxiesStrings.EntityTypeNotFoundShared(type.ShortDisplayName()));\n            }\n\n            throw new InvalidOperationException(CoreStrings.EntityTypeNotFound(type.ShortDisplayName()));\n        }\n\n        return CreateProxy(context, entityType, constructorArguments);\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public virtual Type CreateProxyType(\n        IEntityType entityType)\n        => _generator.ProxyBuilder.CreateClassProxyType(\n            entityType.ClrType,\n            GetInterfacesToProxy(entityType),\n            GenerationOptions);\n","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Proxies/Proxies/Internal/ProxyFactory.cs#L27-L63","documentation":"Thrown by ProxyFactory.Create when FindRuntimeEntityType(type) returns null and the type is not a shared type. This means the CLR type passed in is not part of the EF model at all, so no proxy can be created for it.","triggerScenarios":"Calling ProxyFactory.Create / DbSet-based proxy creation with a Type that has not been registered as an entity in the model (ProxyFactory.cs:37-45). Happens when passing a base class, a DTO, a non-entity class, or a type that is only referenced via an owned/complex type.","commonSituations":"Passing a base type or interface whose concrete subtype is the actual entity; forgetting to register an entity in OnModelCreating; using a DTO/view-model type with the proxy API; namespace collisions where the wrong Type is resolved.","solutions":["Register the type in the model (modelBuilder.Entity<T>() or via DbSet<T> property) so FindRuntimeEntityType resolves it.","Pass the concrete entity Type rather than a base class, interface, or DTO.","If the type should not be an entity, stop using the proxy factory for it — proxies are only for tracked entity types.","Check context.Model.GetEntityTypes() to confirm which types are actually mapped."],"exampleFix":"// before\nvar proxy = context.CreateProxy(typeof(CustomerDto), args); // CustomerDto not in model\n\n// after\n// register the real entity\npublic DbSet<Customer> Customers { get; set; }\nvar proxy = context.CreateProxy(typeof(Customer), args);","handlingStrategy":"validation","validationCode":"// Verify the type is mapped before proxy creation\nvar et = context.Model.FindRuntimeEntityType(type);\nif (et == null)\n    throw new InvalidOperationException($\"{type} is not in the model. Register via DbSet/Entity<T>().\");","typeGuard":"static bool IsMappedEntity(DbContext context, Type t)\n    => context.Model.FindRuntimeEntityType(t) is not null;","tryCatchPattern":null,"preventionTips":["Register all proxyable types as DbSet properties or via modelBuilder.Entity<T>().","Pass the concrete entity type, never a base/DTO/interface.","Add a startup check iterating DbSets to ensure all are in the model."],"tags":["efcore","proxies","entity-not-found","model-configuration"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}