dotnet/efcore · error · InvalidOperationException
Unable to execute a 'ReadItem' query since the 'id' value is
Error message
Unable to execute a 'ReadItem' query since the 'id' value is missing and cannot be generated.
What it means
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.
Source
Thrown at src/EFCore.Cosmos/Query/Internal/CosmosShapedQueryCompilingExpressionVisitor.ReadItemQueryingEnumerable.cs:147
: null;
}
public T Current { get; private set; }
public async ValueTask<bool> MoveNextAsync()
{
try
{
using var _ = _concurrencyDetector?.EnterCriticalSection();
if (_hasExecuted)
{
return false;
}
if (!_readItemEnumerable.TryGetResourceId(out var resourceId))
{
throw new InvalidOperationException(CosmosStrings.ResourceIdMissing);
}
EntityFrameworkMetricsData.ReportQueryExecuting();
_response = await _cosmosQueryContext.CosmosClient.ExecuteReadItemAsync(
_cosmosContainer,
_cosmosPartitionKey,
resourceId,
_cosmosQueryContext.SessionTokenStorage,
_cancellationToken)
.ConfigureAwait(false);
return ShapeResult();
}
catch (Exception exception)
{
if (_exceptionDetector.IsCancellation(exception, _cancellationToken))
{View on GitHub (pinned to dbf9771522)
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.
Example fix
// before
var blog = await context.Blogs.WithPartitionKey(null).Where(b => b.Id == id).FirstAsync();
// after
var blog = await context.Blogs.WithPartitionKey("us-east").Where(b => b.Id == id).FirstAsync(); Defensive patterns
Strategy: validation
Validate before calling
// Ensure all id-defining properties are supplied with concrete values
if (string.IsNullOrEmpty(idValue) || string.IsNullOrEmpty(partitionKeyValue))
throw new ArgumentException("Missing values required for a ReadItem query."); Prevention
- 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.
When it happens
Trigger: 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).
Common situations: 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.
Related errors
- Unable to generate a valid 'id' value to execute a 'ReadItem
- Azure Cosmos DB does not support synchronous I/O. Make sure
- The entity type '{entityType}' does not have a property mapp
- The type of the '{idProperty}' property on '{entityType}' is
- The LINQ expression '{expression}' could not be translated.
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/53deefeff1dbcdf6.
Report an issue: GitHub.