{"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/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Metadata/Internal/DbFunction.cs#L458-L494","documentation":"Nullability propagation only applies to scalar functions (a single value whose NULL behavior can be configured). SetIsNullable throws when called on a DbFunction whose IsScalar is false — i.e. a table-valued function returning IQueryable<T> — because nullable does not apply to a result set.","triggerScenarios":"Calling HasDbFunction(...).CanBeNull / SetIsNullable / builder.IsNullable() on a TVF (method returning IQueryable<T>); common when copy-pasting scalar-function configuration onto a composable TVF.","commonSituations":"Reusing a fluent configuration block for a scalar function on a TVF; refactor converting a scalar function to a TVF without removing the nullability configuration.","solutions":["Remove the nullability configuration (IsNullable / HasNullable) from the TVF DbFunction.","If nullability is required, change the function to return a scalar type so it becomes a scalar DbFunction."],"exampleFix":"// before\npublic IQueryable<Order> ActiveOrders() => throw new NotSupportedException();\nmodelBuilder.HasDbFunction(typeof(AppDb).GetMethod(nameof(ActiveOrders)))\n    .IsNullable(true);  // throws: TVF\n\n// after\nmodelBuilder.HasDbFunction(typeof(AppDb).GetMethod(nameof(ActiveOrders)));\n// do not configure nullability on a table-valued function","handlingStrategy":"validation","validationCode":"var fn = modelBuilder.HasDbFunction(typeof(AppDb).GetMethod(nameof(AppDb.ActiveOrders))!).Metadata;\nif (!fn.IsScalar)\n{\n    // do not call IsNullable / SetIsNullable on this function\n    return;\n}","typeGuard":"static bool CanConfigureNullability(IReadOnlyDbFunction fn) => fn.IsScalar;","tryCatchPattern":null,"preventionTips":["Keep a separate configuration helper for scalar functions vs TVFs so nullability is only ever set on scalars.","When converting a scalar function to a TVF, drop nullability configuration in the same change."],"tags":["relational","dbfunctions","table-valued-functions","nullability"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}