{"record":{"id":"4d30e0fa0957e309","repo":"dotnet/efcore","slug":"isnullable-cannot-be-set-on-dbfunction-functio","errorCode":null,"errorMessage":"'IsNullable' cannot be set on DbFunction '{functionName}' since the function does not represent a scalar function.","messagePattern":"'IsNullable' cannot be set on DbFunction '(.+?)' since the function does not represent a scalar function\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Metadata/Internal/DbFunction.cs","lineNumber":476,"sourceCode":"    public virtual bool IsNullable\n    {\n        get => _nullable;\n        set => SetIsNullable(value, ConfigurationSource.Explicit);\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public virtual bool SetIsNullable(bool nullable, ConfigurationSource configurationSource)\n    {\n        EnsureMutable();\n\n        if (!IsScalar)\n        {\n            throw new InvalidOperationException(RelationalStrings.NonScalarFunctionCannotBeNullable(Name));\n        }\n\n        _nullable = nullable;\n        _nullableConfigurationSource = configurationSource.Max(_nullableConfigurationSource);\n\n        return nullable;\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public virtual ConfigurationSource? GetIsNullableConfigurationSource()\n        => _nullableConfigurationSource;\n\n    /// <summary>","sourceCodeStart":458,"sourceCodeEnd":494,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Metadata/Internal/DbFunction.cs#L458-L494","documentation":"Thrown by DbFunction.SetIsNullable when IsScalar is false (the function returns IQueryable<T>, i.e. it is a table-valued function). Nullability of a return value only makes sense for scalar functions; a TVF returns a row set, so 'nullable' is meaningless and EF rejects the configuration.","triggerScenarios":"Calling builder.IsNullable(...) (HasAnnotation/IsNullable fluent) on a DbFunction that returns IQueryable<T>. Surfaced through InternalDbFunctionBuilder.IsNullable -> Metadata.SetIsNullable.","commonSituations":"Developers apply a generic DbFunction configuration helper that sets IsNullable to every registered function, including TVFs. Or copy scalar-function config onto a TVF.","solutions":["Remove the IsNullable call for table-valued functions; only set it for scalar DbFunctions.","Guard the call: only apply IsNullable when the function is scalar.","Split configuration into scalar vs TVF branches so TVFs skip nullability.","If you intended a scalar function, change the return type to a scalar type first."],"exampleFix":"// before\npublic IQueryable<Order> RecentOrders() => /* tvf */;\nmodelBuilder.HasDbFunction(typeof(Ctx).GetMethod(\"RecentOrders\"))\n    .HasAnnotation(RelationalAnnotationNames.DbFunctionIsNullable, true); // throws\n\n// after\npublic IQueryable<Order> RecentOrders() => /* tvf */;\nmodelBuilder.HasDbFunction(typeof(Ctx).GetMethod(\"RecentOrders\"));\n// (do not set IsNullable on a TVF)","handlingStrategy":"validation","validationCode":"// Only apply IsNullable to scalar functions\nforeach (var fn in modelBuilder.Model.GetDbFunctions().Where(f => f.IsScalar))\n{\n    fn.Builder.IsNullable(true, fromDataAnnotation: true);\n}","typeGuard":"static bool CanSetNullable(IDbFunction fn) => fn.IsScalar;","tryCatchPattern":null,"preventionTips":["Branch DbFunction configuration by IsScalar (scalar vs TVF).","Do not run shared 'configure all DbFunctions' helpers that set IsNullable blindly.","Document which DbFunctions are scalar vs TVF near their declarations."],"tags":["efcore","dbfunction","tvf","nullable","model-building"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}