Add easy support for user-defined niladic functions
Open
area-query
customer-reported
- Dominant language
- C#
- Stars
- 14.8k
- Forks
- 3.4k
- PR merge metrics
- PR metrics pending
Description
We allow users to map arbitrary user functions, but support is missing for niladic ones. The example raised by @Coder3333 [here](https://github.com/dotnet/efcore/issues/32969#issuecomment-2127641343) was for `CURRENT_USER` (note no parentheses).
This can be worked around via manual SQL translation to SqlFunctionExpression:
```c#
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasDbFunction(typeof(BlogContext).GetMethod(nameof(CurrentUser), [])!)
.HasTranslation(_ =>
new SqlFunctionExpression("CURRENT_USER", nullable: false, typeof(string), typeMapping: null));
}
```
Contributor guide
Assessment
This issue has not been assessed yet.