{"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/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Proxies/Proxies/Internal/ProxyFactory.cs#L27-L63","documentation":"Thrown by ProxyFactory.Create when the supplied CLR type is not part of the model at all: FindRuntimeEntityType(type) is null and the type is not registered as shared. This reuses CoreStrings.EntityTypeNotFound. The type was never added to the model via DbSet, OnModelCreating, or Entity<T>().","triggerScenarios":"Calling CreateProxy<T> for a type that has no corresponding entity type in the context's model (not declared in any DbSet, not configured in OnModelCreating).","commonSituations":"Passing a DTO or view-model type to CreateProxy by mistake; typo in the generic argument; calling CreateProxy before the model is built/seeded; using a type from another assembly that was never registered.","solutions":["Add the type to the model: declare a DbSet<T> or call modelBuilder.Entity<T>() in OnModelCreating.","Verify the CLR type passed to CreateProxy exactly matches the registered entity type.","Ensure the DbContext the proxy factory is resolving against is the one that owns the entity type."],"exampleFix":"// before: OrderDetail is not in the model\nvar proxy = context.CreateProxy<OrderDetail>();\n\n// after: register the entity type\npublic DbSet<OrderDetail> OrderDetails { get; set; }\n// or in OnModelCreating:\nmodelBuilder.Entity<OrderDetail>();","handlingStrategy":"validation","validationCode":"// Ensure the type is part of the model before creating a proxy\nvar et = context.Model.FindEntityType(typeof(OrderDetail));\nif (et == null)\n    throw new InvalidOperationException(typeof(OrderDetail).Name + \" is not in the model.\");\nvar proxy = context.CreateProxy<OrderDetail>();","typeGuard":"static bool IsRegisteredEntity(IModel model, Type t) => model.FindEntityType(t) != null;","tryCatchPattern":null,"preventionTips":["Register entity types via DbSet<T> or modelBuilder.Entity<T>() in OnModelCreating.","Verify with context.Model.FindEntityType(type) before proxy creation.","Keep entity types in the same DbContext that owns the model."],"tags":["ef-core","proxies","model-building","entity-not-found","configuration"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}