dotnet/efcore · error · InvalidOperationException

The LINQ expression ' ' could not be translated. Additional…

Error message

The LINQ expression '{expression}' could not be translated. Additional information: {details} Either rewrite the query in a form that can be translated, or switch to client evaluation explicitly by inserting a call to 'AsEnumerable', 'AsAsyncEnumerable', 'ToList', or 'ToListAsync'. See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.

What it means

The detailed variant of translation failure: same throw site as 617, but TranslationErrorDetails is non-null so EF Core appends the collected per-sub-expression translation errors. Use the details to pinpoint which sub-expression of the LINQ tree failed.

Solutions

  1. Read the {details} segment to find the specific sub-expression that failed and address it first.
  2. Rewrite or remove the flagged sub-expression; push down only translatable constructs.
  3. Switch the failing portion to client evaluation with AsEnumerable/ToList.
  4. Upgrade the provider if the detail indicates a known translation gap.

Example fix

// before
var q = ctx.Orders.Where(o => o.Items.Sum(i => i.Weight * i.Count) > 100);
// detail: Sum over expression not supported -> precompute
// after
var q = ctx.Orders
    .AsEnumerable()
    .Where(o => o.Items.Sum(i => i.Weight * i.Count) > 100);
Defensive patterns

Strategy: fallback

Try / catch

try { await query.ToListAsync(); }
catch (InvalidOperationException ex) when (ex.Message.Contains("could not be translated"))
{
    // ex.Message includes Additional information: <details> — log it for diagnosis.
    logger.LogError(ex, "Translation failed with details");
    var fallback = query.AsEnumerable(); // client-side
}

Prevention

When it happens

Trigger: Same TVF/db-function argument translation failure, but the translator collected sub-expression error details (e.g. 'could not translate MyClientMethod()' or 'Sum over byte not supported').

Common situations: Complex queries where multiple parts may fail; provider-specific gaps that surface with explanatory detail.

Related errors


AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11). Data as JSON: /api/errors/cec9cdcd8edf60a9. Report an issue: GitHub.

Appendix: source

Thrown at src/EFCore.Relational/Query/RelationalQueryableMethodTranslatingExpressionVisitor.cs:140

                    {
                        string call;
                        var methodInfo = function.DbFunctions.Last().MethodInfo;
                        if (methodInfo != null)
                        {
                            var methodCall = Expression.Call(
                                // Declaring types would be derived db context.
                                Expression.Default(methodInfo.DeclaringType!),
                                methodInfo,
                                tableValuedFunctionQueryRootExpression.Arguments);

                            call = methodCall.Print();
                        }
                        else
                        {
                            call = $"{function.DbFunctions.Last().Name}()";
                        }

                        throw new InvalidOperationException(
                            TranslationErrorDetails == null
                                ? CoreStrings.TranslationFailed(call)
                                : CoreStrings.TranslationFailedWithDetails(call, TranslationErrorDetails));
                    }

                    arguments.Add(sqlArgument);
                }

                var entityType = tableValuedFunctionQueryRootExpression.EntityType;
                var alias = _sqlAliasManager.GenerateTableAlias(function);
                var translation = new TableValuedFunctionExpression(alias, function, arguments);
                var queryExpression = CreateSelect(entityType, translation);

                return CreateShapedQueryExpression(entityType, queryExpression);
            }

            case EntityQueryRootExpression entityQueryRootExpression
                when entityQueryRootExpression.GetType() == typeof(EntityQueryRootExpression)

View on GitHub (pinned to 3a2006ef56)