Path: redb/redb.Core/Query/Sql.cs
Snapshot: redb, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb
Page: https://redbase.app/src/dev-2026-12-06/redb/redb.Core/Query/Sql.cs
----
using System;
namespace redb.Core.Query;
///
/// SQL functions for use in LINQ expressions.
/// Translated to native SQL by the active provider during query generation.
///
public static class Sql
{
///
/// Call custom SQL function.
///
/// Return value type
/// SQL function name (e.g.: "COALESCE", "POWER", "my_custom_func")
/// Function arguments (properties, constants, expressions)
/// Function result (used only for typing)
///
/// COALESCE(pvt."Stock", 0)
/// .Where(p => Sql.Function<long>("COALESCE", p.Stock, 0) > 50)
///
/// POWER(pvt."Age", 2)
/// .Where(p => Sql.Function<double>("POWER", p.Age, 2) > 100)
///
/// my_custom_func(pvt."Name", pvt."Code")
/// .Where(p => Sql.Function<string>("my_custom_func", p.Name, p.Code) == "result")
///
public static TResult Function(string functionName, params object?[] args)
{
throw new InvalidOperationException(
"Sql.Function() can only be used within LINQ expressions (Where, WhereRedb, etc.). " +
"It cannot be called directly.");
}
}