Table of Contents

Class SqlIntervalPartExpression

Namespace
LinqToDB.Internal.SqlQuery
Assembly
linq2db.dll

A component or a total of an interval, expressed in a requested unit.

public sealed class SqlIntervalPartExpression : SqlExpressionBase, ISqlExpression, IQueryElement, IEquatable<ISqlExpression>
Inheritance
object
SqlIntervalPartExpression
Implements
Inherited Members
Extension Methods

Remarks

Component reproduces TimeSpan.Hours, truncating toward zero as CLR integer division does; Total reproduces TimeSpan.TotalHours and keeps the fraction. Provider division and modulo do not agree on negative values, so lowering must express the truncation explicitly rather than lean on the database's own rules.

Constructors

SqlIntervalPartExpression(ISqlExpression, SqlIntervalUnit, SqlIntervalPartKind, DbDataType, SqlIntervalUnit?)

public SqlIntervalPartExpression(ISqlExpression interval, SqlIntervalUnit unit, SqlIntervalPartKind kind, DbDataType type, SqlIntervalUnit? within = null)

Parameters

interval ISqlExpression
unit SqlIntervalUnit
kind SqlIntervalPartKind
type DbDataType
within SqlIntervalUnit?

Properties

ElementType

AST node type.

public override QueryElementType ElementType { get; }

Property Value

QueryElementType

Interval

Interval the part is taken from.

public ISqlExpression Interval { get; }

Property Value

ISqlExpression

Kind

Whether a component within an enclosing unit or the whole interval is requested.

public SqlIntervalPartKind Kind { get; }

Property Value

SqlIntervalPartKind

Precedence

public override int Precedence { get; }

Property Value

int

SystemType

public override Type? SystemType { get; }

Property Value

Type

Type

Result type - integral for Component, floating point for Total.

public DbDataType Type { get; }

Property Value

DbDataType

Unit

Unit the result is expressed in.

public SqlIntervalUnit Unit { get; }

Property Value

SqlIntervalUnit

Within

The unit a Component is counted within, or null when it is not counted within anything - TimeSpan.Days is the whole day count and does not wrap. Meaningless for Total.

public SqlIntervalUnit? Within { get; }

Property Value

SqlIntervalUnit?

Remarks

Stated rather than implied. "The next coarser unit" cannot express the two readings the same unit has - TimeSpan.Microseconds counts within the millisecond while DATEPART(microsecond, ...) counts within the second - and it is the enclosing unit, not this one, that decides whether a component survives a coarse measurement: nanoseconds within a microsecond stay meaningful at tick resolution, because a tick is a hundred of them.

Methods

Accept(QueryElementVisitor)

Visitor support.

public override IQueryElement Accept(QueryElementVisitor visitor)

Parameters

visitor QueryElementVisitor

Returns

IQueryElement

CanBeNullable(NullabilityContext)

public override bool CanBeNullable(NullabilityContext nullability)

Parameters

nullability NullabilityContext

Returns

bool

Equals(ISqlExpression, Func<ISqlExpression, ISqlExpression, bool>)

public override bool Equals(ISqlExpression other, Func<ISqlExpression, ISqlExpression, bool> comparer)

Parameters

other ISqlExpression
comparer Func<ISqlExpression, ISqlExpression, bool>

Returns

bool

GetElementHashCode()

public override int GetElementHashCode()

Returns

int

Modify(ISqlExpression, SqlIntervalUnit, SqlIntervalPartKind, DbDataType, SqlIntervalUnit?)

public void Modify(ISqlExpression interval, SqlIntervalUnit unit, SqlIntervalPartKind kind, DbDataType type, SqlIntervalUnit? within)

Parameters

interval ISqlExpression
unit SqlIntervalUnit
kind SqlIntervalPartKind
type DbDataType
within SqlIntervalUnit?

ToString(QueryElementTextWriter)

Generates debug text representation of AST node.

public override QueryElementTextWriter ToString(QueryElementTextWriter writer)

Parameters

writer QueryElementTextWriter

Returns

QueryElementTextWriter