{"record":{"id":"1ba1a573205c8645","repo":"dotnet/efcore","slug":"missing-iffalse-in-nameof-system-linq-expressions","errorCode":null,"errorMessage":"Missing IfFalse in {nameof(System.Linq.Expressions.ConditionalExpression)} in expression context","messagePattern":"Missing IfFalse in (.+?) in expression context","errorType":"exception","errorClass":"NotSupportedException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs","lineNumber":837,"sourceCode":"        ConditionalExpression conditional,\n        IdentifierNameSyntax? lowerableAssignmentVariable)\n    {\n        // ConditionalExpression can be an expression or an if/else statement.\n        var test = Translate<ExpressionSyntax>(conditional.Test);\n\n        var isFalseAbsent = conditional.IfFalse is DefaultExpression defaultIfFalse && defaultIfFalse.Type == typeof(void);\n\n        switch (_context)\n        {\n            case ExpressionContext.Statement:\n                return TranslateConditionalStatement(conditional);\n\n            case ExpressionContext.Expression:\n            case ExpressionContext.ExpressionLambda:\n            {\n                if (isFalseAbsent)\n                {\n                    throw new NotSupportedException(\n                        $\"Missing {nameof(ConditionalExpression.IfFalse)} in \"\n                        + \"{nameof(System.Linq.Expressions.ConditionalExpression)} in expression context\");\n                }\n\n                var parentLiftedState = _liftedState;\n                _liftedState = parentLiftedState.CreateChild();\n\n                // If we're in a lambda body, we try to translate as an expression if possible (i.e. no blocks in the true/false arms).\n                using (ChangeContext(ExpressionContext.Expression))\n                {\n                    var ifTrue = Translate(conditional.IfTrue);\n                    var ifFalse = Translate(conditional.IfFalse);\n\n                    if (ifTrue is not ExpressionSyntax ifTrueExpression\n                        || ifFalse is not ExpressionSyntax ifFalseExpression)\n                    {\n                        throw new InvalidOperationException(\"Trying to evaluate a non-expression condition in expression context\");\n                    }","sourceCodeStart":819,"sourceCodeEnd":855,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Design/Query/Internal/LinqToCSharpSyntaxTranslator.cs#L819-L855","documentation":"Thrown in TranslateConditional (expression context) when IfFalse is a DefaultExpression of void - a conditional with no false branch cannot be rendered as a C# ternary '?:'. Note: the source has a string-interpolation bug (missing $ on the second literal) so '{nameof(System.Linq.Expressions.ConditionalExpression)}' appears literally in the runtime message. Part of EF Core's LINQ-to-C# syntax translation.","triggerScenarios":"A ConditionalExpression constructed with Condition(test, ifTrue) (no ifFalse, defaults to void DefaultExpression) being translated in expression context.","commonSituations":"Manual expression-tree construction omitting the false branch; expression trees from query translation producing single-armed conditionals that then get re-translated in expression context.","solutions":["Provide an explicit IfFalse branch when constructing the ConditionalExpression.","Translate in statement context (if/else) if the false branch is genuinely absent."],"exampleFix":"// before\nExpression.Condition(test, ifTrue)\n// after\nExpression.Condition(test, ifTrue, Expression.Constant(null, ifTrue.Type))","handlingStrategy":"validation","validationCode":"// Ensure Conditionals translated in expression context have an IfFalse branch\nforeach (var cond in expr.DescendantsAndSelf().OfType<ConditionalExpression>())\n{\n    var isFalseAbsent = cond.IfFalse is DefaultExpression d && d.Type == typeof(void);\n    if (isFalseAbsent)\n        throw new InvalidOperationException(\n            \"ConditionalExpression has no IfFalse branch; cannot translate in expression context.\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass an explicit ifFalse when constructing Expression.Condition for expression-context translation.","Use statement context (if/else) when the false branch is intentionally absent."],"tags":["efcore","expression-trees","conditional","ternary"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}