Show / Hide Table of Contents

Class Case

Represents a SQL searched CASE expression with one or more WHEN/THEN branches and an optional ELSE.

Inheritance
object
QueryElement
Argument
Case
Implements
ICloneable
Inherited Members
Argument.Equal(Argument)
Argument.UnEqual(Argument)
Argument.LessThan(Argument)
Argument.LessThanOrEqual(Argument)
Argument.GreaterThan(Argument)
Argument.GreaterThanOrEqual(Argument)
Argument.Like(Argument)
Argument.Like(string)
Argument.NotLike(Argument)
Argument.NotBetween(Argument, Argument)
Argument.Between(Argument, Argument)
Argument.In(params Argument[])
Argument.HasAny(params Argument[])
Argument.HasAll(params Argument[])
Argument.MissingAny(params Argument[])
Argument.MissingAll(params Argument[])
Argument.IsNull()
Argument.IsNotNull()
Argument.NotIn(params Argument[])
Argument.HasFlag(Argument)
Argument.HasNoFlag(Argument)
Argument.ToArgumentArray<T>(T[])
Argument.ToArgumentArray<T>(T[], bool)
Argument.GetSubElements()
Argument.Alias
Argument.DataType
Argument.Size
object.ToString()
object.Equals(object)
object.Equals(object, object)
object.ReferenceEquals(object, object)
object.GetHashCode()
object.GetType()
object.MemberwiseClone()
Namespace: SuperOffice.Data.SQL
Assembly: SoDataBase.dll
Syntax
public class Case : Argument, ICloneable
Remarks

Generates SQL of the form:

CASE
    WHEN condition1 THEN result1
    WHEN condition2 THEN result2
    ...
    [ELSE elseResult]
END
Conditions are evaluated sequentially; the first true condition determines the result. If no condition matches and no ELSE is provided, SQL returns NULL.

All THEN and ELSE arguments must have the same FieldDataType. The DataType of the CASE expression is inherited from the first THEN branch.

Parameters inside the CASE expression are always rendered as @Pn placeholders, even when the CASE appears in a SELECT clause (where parameters would normally be inlined). The Dialect temporarily switches to SqlSection.Restriction mode while rendering the CASE to achieve this.

To construct a CASE expression, use the fluent builder via the factory:

S.FieldExpression.Case()
    .When(condition1, result1)
    .When(condition2, result2)
    .Else(elseResult)

Constructors

Case()

Create an empty CASE expression. Add branches with When(Restriction, Argument) and optionally Else(Argument).

Declaration
public Case()
Remarks

At least one When(Restriction, Argument) branch must be added before the CASE can be rendered. The DataType is determined by the first WHEN branch added.

Properties

ElseArgument

The optional ELSE result. Null means SQL returns NULL when no condition matches.

Declaration
public Argument ElseArgument { get; }
Property Value
Type Description
Argument
Remarks

Generates SQL of the form:

CASE
    WHEN condition1 THEN result1
    WHEN condition2 THEN result2
    ...
    [ELSE elseResult]
END
Conditions are evaluated sequentially; the first true condition determines the result. If no condition matches and no ELSE is provided, SQL returns NULL.

All THEN and ELSE arguments must have the same FieldDataType. The DataType of the CASE expression is inherited from the first THEN branch.

Parameters inside the CASE expression are always rendered as @Pn placeholders, even when the CASE appears in a SELECT clause (where parameters would normally be inlined). The Dialect temporarily switches to SqlSection.Restriction mode while rendering the CASE to achieve this.

To construct a CASE expression, use the fluent builder via the factory:

S.FieldExpression.Case()
    .When(condition1, result1)
    .When(condition2, result2)
    .Else(elseResult)

HasElse

True if an ELSE branch was provided.

Declaration
public bool HasElse { get; }
Property Value
Type Description
bool
Remarks

Generates SQL of the form:

CASE
    WHEN condition1 THEN result1
    WHEN condition2 THEN result2
    ...
    [ELSE elseResult]
END
Conditions are evaluated sequentially; the first true condition determines the result. If no condition matches and no ELSE is provided, SQL returns NULL.

All THEN and ELSE arguments must have the same FieldDataType. The DataType of the CASE expression is inherited from the first THEN branch.

Parameters inside the CASE expression are always rendered as @Pn placeholders, even when the CASE appears in a SELECT clause (where parameters would normally be inlined). The Dialect temporarily switches to SqlSection.Restriction mode while rendering the CASE to achieve this.

To construct a CASE expression, use the fluent builder via the factory:

S.FieldExpression.Case()
    .When(condition1, result1)
    .When(condition2, result2)
    .Else(elseResult)

WhenClauses

The WHEN/THEN branches, evaluated in order.

Declaration
public IReadOnlyList<(Restriction Condition, Argument Result)> WhenClauses { get; }
Property Value
Type Description
IReadOnlyList<(Restriction Condition, Argument Result)>
Remarks

Generates SQL of the form:

CASE
    WHEN condition1 THEN result1
    WHEN condition2 THEN result2
    ...
    [ELSE elseResult]
END
Conditions are evaluated sequentially; the first true condition determines the result. If no condition matches and no ELSE is provided, SQL returns NULL.

All THEN and ELSE arguments must have the same FieldDataType. The DataType of the CASE expression is inherited from the first THEN branch.

Parameters inside the CASE expression are always rendered as @Pn placeholders, even when the CASE appears in a SELECT clause (where parameters would normally be inlined). The Dialect temporarily switches to SqlSection.Restriction mode while rendering the CASE to achieve this.

To construct a CASE expression, use the fluent builder via the factory:

S.FieldExpression.Case()
    .When(condition1, result1)
    .When(condition2, result2)
    .Else(elseResult)

Methods

Clone()

Deep-clone this CASE expression. All WHEN conditions, THEN results, and the ELSE result are cloned. Parameter values are shared between the original and the clone.

Declaration
public override object Clone()
Returns
Type Description
object
Overrides
QueryElement.Clone()
Remarks

Generates SQL of the form:

CASE
    WHEN condition1 THEN result1
    WHEN condition2 THEN result2
    ...
    [ELSE elseResult]
END
Conditions are evaluated sequentially; the first true condition determines the result. If no condition matches and no ELSE is provided, SQL returns NULL.

All THEN and ELSE arguments must have the same FieldDataType. The DataType of the CASE expression is inherited from the first THEN branch.

Parameters inside the CASE expression are always rendered as @Pn placeholders, even when the CASE appears in a SELECT clause (where parameters would normally be inlined). The Dialect temporarily switches to SqlSection.Restriction mode while rendering the CASE to achieve this.

To construct a CASE expression, use the fluent builder via the factory:

S.FieldExpression.Case()
    .When(condition1, result1)
    .When(condition2, result2)
    .Else(elseResult)

Else(Argument)

Set the ELSE branch, returned when no WHEN condition matches.

Declaration
public Case Else(Argument elseResult)
Parameters
Type Name Description
Argument elseResult

The ELSE result. Must have the same DataType as the THEN branches.

Returns
Type Description
Case

This CASE expression, for fluent chaining.

Remarks

Generates SQL of the form:

CASE
    WHEN condition1 THEN result1
    WHEN condition2 THEN result2
    ...
    [ELSE elseResult]
END
Conditions are evaluated sequentially; the first true condition determines the result. If no condition matches and no ELSE is provided, SQL returns NULL.

All THEN and ELSE arguments must have the same FieldDataType. The DataType of the CASE expression is inherited from the first THEN branch.

Parameters inside the CASE expression are always rendered as @Pn placeholders, even when the CASE appears in a SELECT clause (where parameters would normally be inlined). The Dialect temporarily switches to SqlSection.Restriction mode while rendering the CASE to achieve this.

To construct a CASE expression, use the fluent builder via the factory:

S.FieldExpression.Case()
    .When(condition1, result1)
    .When(condition2, result2)
    .Else(elseResult)

GetMainField()

Return the representative FieldInfo for this CASE expression. Returns the first non-null main field found by checking THEN results in order, then the ELSE result. Used by the query framework to determine table involvement.

Declaration
public override FieldInfo GetMainField()
Returns
Type Description
FieldInfo
Overrides
Argument.GetMainField()
Remarks

Generates SQL of the form:

CASE
    WHEN condition1 THEN result1
    WHEN condition2 THEN result2
    ...
    [ELSE elseResult]
END
Conditions are evaluated sequentially; the first true condition determines the result. If no condition matches and no ELSE is provided, SQL returns NULL.

All THEN and ELSE arguments must have the same FieldDataType. The DataType of the CASE expression is inherited from the first THEN branch.

Parameters inside the CASE expression are always rendered as @Pn placeholders, even when the CASE appears in a SELECT clause (where parameters would normally be inlined). The Dialect temporarily switches to SqlSection.Restriction mode while rendering the CASE to achieve this.

To construct a CASE expression, use the fluent builder via the factory:

S.FieldExpression.Case()
    .When(condition1, result1)
    .When(condition2, result2)
    .Else(elseResult)

When(Restriction, Argument)

Add a WHEN/THEN branch. Conditions are evaluated in the order they are added.

Declaration
public Case When(Restriction condition, Argument result)
Parameters
Type Name Description
Restriction condition

The WHEN condition.

Argument result

The THEN result. Must have the same DataType as the first branch.

Returns
Type Description
Case

This CASE expression, for fluent chaining.

Remarks

Generates SQL of the form:

CASE
    WHEN condition1 THEN result1
    WHEN condition2 THEN result2
    ...
    [ELSE elseResult]
END
Conditions are evaluated sequentially; the first true condition determines the result. If no condition matches and no ELSE is provided, SQL returns NULL.

All THEN and ELSE arguments must have the same FieldDataType. The DataType of the CASE expression is inherited from the first THEN branch.

Parameters inside the CASE expression are always rendered as @Pn placeholders, even when the CASE appears in a SELECT clause (where parameters would normally be inlined). The Dialect temporarily switches to SqlSection.Restriction mode while rendering the CASE to achieve this.

To construct a CASE expression, use the fluent builder via the factory:

S.FieldExpression.Case()
    .When(condition1, result1)
    .When(condition2, result2)
    .Else(elseResult)

Implements

ICloneable

Extension Methods

EnumUtil.MapEnums<From, To>(From)
Converters.MapEnums<From, To>(From)
ObjectExtensions.AssignByReflection<T>(T, T)
ObjectExtensions.GraphCopy<T>(T)
© SuperOffice. All rights reserved.
SuperOffice |  Community |  Release Notes |  Privacy |  Site feedback |  Search Docs |  About Docs |  Contribute |  Back to top