{"record":{"id":"53deefeff1dbcdf6","repo":"dotnet/efcore","slug":"unable-to-execute-a-readitem-query-since-the-id","errorCode":null,"errorMessage":"Unable to execute a 'ReadItem' query since the 'id' value is missing and cannot be generated.","messagePattern":"Unable to execute a 'ReadItem' query since the 'id' value is missing and cannot be generated\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.ReadItemQueryingEnumerable.cs","lineNumber":147,"sourceCode":"                    : null;\n            }\n\n            public T Current { get; private set; }\n\n            public async ValueTask<bool> MoveNextAsync()\n            {\n                try\n                {\n                    using var _ = _concurrencyDetector?.EnterCriticalSection();\n\n                    if (_hasExecuted)\n                    {\n                        return false;\n                    }\n\n                    if (!_readItemEnumerable.TryGetResourceId(out var resourceId))\n                    {\n                        throw new InvalidOperationException(CosmosStrings.ResourceIdMissing);\n                    }\n\n                    EntityFrameworkMetricsData.ReportQueryExecuting();\n\n                    _response = await _cosmosQueryContext.CosmosClient.ExecuteReadItemAsync(\n                            _cosmosContainer,\n                            _cosmosPartitionKey,\n                            resourceId,\n                            _cosmosQueryContext.SessionTokenStorage,\n                            _cancellationToken)\n                        .ConfigureAwait(false);\n\n                    return ShapeResult();\n                }\n                catch (Exception exception)\n                {\n                    if (_exceptionDetector.IsCancellation(exception, _cancellationToken))\n                    {","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.ReadItemQueryingEnumerable.cs#L129-L165","documentation":"Thrown inside the ReadItem async enumerator when TryGetResourceId returns false, meaning the 'id' value needed for a point read is missing and cannot be generated from the configured id definition. Unlike error 88 (which fires during id string generation), this fires at execution time when the runtime values do not yield a usable id.","triggerScenarios":"Executing a query the provider routes to a ReadItem point read, but the runtime parameter/constant values for the id-defining properties do not produce a valid id (e.g. a required id property value was never supplied, or the id definition could not match the query shape).","commonSituations":"Querying by a property that is not part of the configured id definition while the provider still attempts a ReadItem. Misconfigured JsonIdDefinition after a model change. Passing a null parameter value for an id part.","solutions":["Verify the entity's JsonIdDefinition matches the properties used in the query predicate.","Ensure all id-defining property values are supplied as non-null constants or parameters.","If the query cannot be a point read, restructure it so the provider uses a SQL query instead (e.g. query on a non-id property).","Check for model configuration drift after upgrading EF Core Cosmos."],"exampleFix":"// before\nvar blog = await context.Blogs.WithPartitionKey(null).Where(b => b.Id == id).FirstAsync();\n// after\nvar blog = await context.Blogs.WithPartitionKey(\"us-east\").Where(b => b.Id == id).FirstAsync();","handlingStrategy":"validation","validationCode":"// Ensure all id-defining properties are supplied with concrete values\nif (string.IsNullOrEmpty(idValue) || string.IsNullOrEmpty(partitionKeyValue))\n    throw new ArgumentException(\"Missing values required for a ReadItem query.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Confirm the JsonIdDefinition matches the predicate properties.","Supply all id-defining values as non-null parameters.","If a point read is not possible, query on a non-id property to force a SQL query."],"tags":["cosmos","read-item","id","query","execution"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}