dotnet/efcore · error · InvalidOperationException
Translation of '{expression}' failed. Either the query sourc
Error message
Translation of '{expression}' failed. Either the query source is not an entity type, or the specified property does not exist on the entity type. What it means
Thrown when EF.Property(source, "Name") cannot be bound because the source is not an entity/struct type or the named property does not exist on it. TryBindMember returns null, so the translator throws QueryUnableToTranslateEFProperty to make the missing mapping explicit rather than emitting null.
Source
Thrown at src/EFCore.InMemory/Query/Internal/InMemoryExpressionTranslatingExpressionVisitor.cs:656
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected override Expression VisitMethodCall(MethodCallExpression methodCallExpression)
{
if (methodCallExpression.Method.IsGenericMethod
&& methodCallExpression.Method.GetGenericMethodDefinition() == ExpressionExtensions.ValueBufferTryReadValueMethod)
{
return methodCallExpression;
}
// EF.Property case
if (methodCallExpression.TryGetEFPropertyArguments(out var source, out var propertyName))
{
return TryBindMember(Visit(source), MemberIdentity.Create(propertyName), methodCallExpression.Type)
?? throw new InvalidOperationException(CoreStrings.QueryUnableToTranslateEFProperty(methodCallExpression.Print()));
}
// EF Indexer property
if (methodCallExpression.TryGetIndexerArguments(_model, out source, out propertyName))
{
return TryBindMember(Visit(source), MemberIdentity.Create(propertyName), methodCallExpression.Type)
?? QueryCompilationContext.NotTranslatedExpression;
}
// Subquery case
var subqueryTranslation = _queryableMethodTranslatingExpressionVisitor.TranslateSubquery(methodCallExpression);
if (subqueryTranslation != null)
{
var subquery = (InMemoryQueryExpression)subqueryTranslation.QueryExpression;
if (subqueryTranslation.ResultCardinality == ResultCardinality.Enumerable)
{
return QueryCompilationContext.NotTranslatedExpression;
}View on GitHub (pinned to 3a2006ef56)
Solutions
- Verify the property name spelling matches a mapped property on the entity type.
- Ensure the source expression resolves to a tracked entity type, not a projection or DTO.
- If the value is a shadow property, confirm it is configured in the model (e.g. via .Property<string>("Foo")).
- Replace EF.Property with a normal member access where possible, since EF translates mapped properties directly.
Example fix
// before var q = db.Users.Select(u => EF.Property<string>(u, "Nmae")); // after var q = db.Users.Select(u => u.Name);
Defensive patterns
Strategy: validation
Validate before calling
// Validate the EF.Property target before building the query
var et = dbContext.Model.FindEntityType(typeof(User));
if (et?.FindProperty("Name") is null)
throw new InvalidOperationException("Property 'Name' is not mapped on User"); Type guard
static bool HasMappedProperty(IModel model, Type clrType, string name)
=> model.FindEntityType(clrType)?.FindProperty(name) is not null; Prevention
- Prefer direct member access over EF.Property when possible.
- Spell property names exactly as mapped; consider nameof(EntityType.Property).
- Confirm shadow properties are declared in the model before referencing them.
When it happens
Trigger: An expression tree contains EF.Property(obj, "Foo") where obj does not resolve to a known entity, or "Foo" is not a mapped property/shadow property/indexer on that entity's model.
Common situations: Referencing a property by a misspelled name, a renamed column, or a property that was removed from the model. Calling EF.Property on a DTO or anonymous projection rather than an entity. Accessing a navigation that was configured as not-mapped.
Related errors
- The LINQ expression '{expression}' could not be translated.
- Cannot translate the '{comparisonOperator}' on an expression
- Cannot translate '{comparisonOperator}' on a subquery expres
- The '{parameter}' value passed to '{methodName}' must be a c
- The entity type '{entityType}' has a defining query configur
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/8accd77c51c3887d.
Report an issue: GitHub.