{"record":{"id":"806f27eb8003891b","repo":"dotnet/efcore","slug":"the-entity-type-entitytype-does-not-have-a-pro-806f27","errorCode":null,"errorMessage":"The entity type '{entityType}' does not have a property mapped to the 'id' property in the database. Add a property mapped to 'id'.","messagePattern":"The entity type '(.+?)' does not have a property mapped to the 'id' property in the database\\. Add a property mapped to 'id'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Storage/Internal/CosmosStructuralTypeSerializer.cs","lineNumber":84,"sourceCode":"        _ordinalKeyProperty = structuralType.GetProperties().SingleOrDefault(p => p.IsOrdinalKeyProperty());\n        _scalarProperties =\n        [\n            .. structuralType.GetProperties().Where(p => p.IsPersisted() && p != _discriminatorProperty?.Property).Select(p\n                => (p, p.GetJsonPropertyName(),\n                    p.GetJsonValueReaderWriter()\n                    ?? p.GetTypeMapping().JsonValueReaderWriter\n                    ?? throw new UnreachableException(\"Property without JsonValueReaderWriter\")))\n        ];\n        _complexProperties =\n            [.. structuralType.GetComplexProperties().Select(cp => (cp, cp.GetJsonPropertyName(), provider.Get(cp.ComplexType)))];\n\n        if (structuralType is IEntityType entityType)\n        {\n            if (entityType.IsDocumentRoot())\n            {\n                _jsonIdProperty = structuralType.GetProperties()\n                        .FirstOrDefault(p => p.GetJsonPropertyName() == CosmosJsonIdConvention.IdPropertyJsonName)\n                    ?? throw new InvalidOperationException(CosmosStrings.NoIdProperty(structuralType.DisplayName()));\n                _container = entityType.GetContainer()\n                    ?? throw new UnreachableException(\"Document root entity type does not have container.\");\n            }\n\n            _navigations =\n            [\n                .. entityType.GetNavigations().Where(n => n.ForeignKey.IsOwnership && !n.IsOnDependent).Select(n\n                    => (n,\n                        n.TargetEntityType.GetContainingPropertyName()\n                        ?? throw new UnreachableException(\"Owned entity without containing property name\"),\n                        provider.Get(n.TargetEntityType)))\n            ];\n        }\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","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Storage/Internal/CosmosStructuralTypeSerializer.cs#L66-L102","documentation":"Every Cosmos document root entity type must have a property that maps to the JSON 'id' field (Cosmos requires it as the document's primary key). During serializer construction, if no property on a document-root entity resolves to the JSON name 'id', the provider throws NoIdProperty. The Cosmos convention normally creates this property, so hitting the error means the convention was suppressed or a custom configuration removed it.","triggerScenarios":"A document-root entity type (IsDocumentRoot() true) where no property's GetJsonPropertyName() equals 'id'. Usually because the user explicitly removed the id property, changed its JSON name, or disabled the Cosmos id convention. See CosmosStructuralTypeSerializer.cs:84-87.","commonSituations":"Overriding the JSON name of the id property (e.g. ToJsonProperty(\"identifier\")) without providing another 'id'-mapped property. Removing conventions including CosmosJsonIdConvention. Renaming the Id property and breaking the convention mapping.","solutions":["Add a property and ensure its JSON name is 'id' (e.g. .ToJsonProperty(\"id\") or let the default convention create one).","Do not disable/replace CosmosJsonIdConvention unless you also configure an explicit 'id' property.","If you renamed the Id CLR property, map it back: .Property(x => x.Key).ToJsonProperty(\"id\")."],"exampleFix":"// before\nmodelBuilder.Entity<Order>()\n    .Property(o => o.Key)\n    .ToJsonProperty(\"identifier\"); // no 'id' property -> throws\n\n// after\nmodelBuilder.Entity<Order>()\n    .Property(o => o.Key)\n    .ToJsonProperty(\"id\");","handlingStrategy":"validation","validationCode":"// Validate every document-root entity has an 'id'-mapped property\nforeach (var et in dbContext.Model.GetEntityTypes().Where(t => t.IsDocumentRoot()))\n{\n    var hasId = et.GetProperties().Any(p => p.GetJsonPropertyName() == \"id\");\n    if (!hasId) throw new InvalidOperationException($\"{et.DisplayName()} has no 'id' property.\");\n}","typeGuard":null,"tryCatchPattern":"try { await dbContext.Database.EnsureCreatedAsync(ct); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"mapped to 'id'\"))\n{\n    // add/repair an 'id'-mapped property, then retry.\n}","preventionTips":["Do not disable the CosmosJsonIdConvention.","Keep the id property's JSON name as 'id'.","Add a model test asserting each root has an 'id'-mapped property."],"tags":["cosmos","id-property","document-root","conventions","model-configuration"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}