Constants in Fluent BQL

You can use predefined constants (such as integer Zero, datetime Now, Today, and MaxDate, string StringEmpty, and the Boolean values True and False) in fluent BQL queries without any changes.

If you need to use a custom constant in a fluent BQL query, you define this constant by using the class that corresponds to the C# type of the constant. The following table lists the constant classes that correspond to C# types.
C# Type Fluent BQL Type
bool BqlBool.Constant<TSelf>
byte BqlByte.Constant<TSelf>
short BqlShort.Constant<TSelf>
int BqlInt.Constant<TSelf>
long BqlLong.Constant<TSelf>
float BqlFloat.Constant<TSelf>
double BqlDouble.Constant<TSelf>
decimal BqlDecimal.Constant<TSelf>
Guid BqlGuid.Constant<TSelf>
DateTime BqlDateTime.Constant<TSelf>
String BqlString.Constant<TSelf>
The following code shows an example of the decimal_0 constant declaration.
public class decimal_0 : PX.Data.BQL.BqlDecimal.Constant<decimal_0> 
{ 
  public decimal_0()
    : base(0m)
  {
  }
}

Simultaneous Use of Constants in Fluent BQL and Traditional BQL

The predefined constants and the constants defined as described in the previous section can be used in traditional BQL without any changes.

The constants defined in the traditional BQL style (that is, derived from the Constant<Type> class) can be used in the fluent BQL queries if you wrap these constants in the Use<>.As[Type] class, where [Type] is one of the following: Bool, Byte, Short, Int, Long, Float, Double, Decimal, Guid, DateTime, or String.

The following code shows the declaration of the decimal_0 constant in traditional BQL style and its use in a fluent BQL comparison.
publicclass decimal_0 : Constant<Decimal>
{
    public decimal_0()
        : base(0m)
    {
    }
}

SelectFrom<Table>.
    Where<Table.decimalField.AsDecimal.IsEqual<Use<decimal_0>.AsDecimal>>.
    View records;

Although the constants in the traditional BQL style can be used in fluent BQL queries, we recommend that you use the fluent BQL style of constant declaration for simplicity.