Table of Contents

Enum DurationUnit

Namespace
LinqToDB.Mapping
Assembly
linq2db.dll

Unit in which a TimeSpan duration is stored in a database column.

public enum DurationUnit
Extension Methods

Fields

Day = 7

Days, always exactly 24 hours.

Hour = 6

Hours.

Microsecond = 2

Microseconds.

Millisecond = 3

Milliseconds.

Minute = 5

Minutes.

Nanosecond = 0

Nanoseconds. Note that TimeSpan resolution is 100 nanoseconds, so stored values are always multiples of 100 and reading a finer value cannot be represented exactly.

The only unit finer than a tick, and the one the server cannot compute with. A value stored in it round trips, but reaching a tick count from it is a division, and no lowering performs one - integer division rounds a negative value differently from one provider to the next, so a chosen rule would answer differently depending on the database. In consequence a member asked for in SQL is refused rather than answered, and so is a comparison or a membership test against a column declared in any other unit, since the two have no unit they can meet in. A plain projection is unaffected: the column is read and the member computed in .NET, which answers exactly.

Second = 4

Seconds.

Tick = 1

100-nanosecond units, matching Ticks. This is the only unit that can represent every TimeSpan value exactly.

Remarks

Calendar units such as month or year cannot be listed: a TimeSpan is a fixed-length duration and their length depends on the point in time they are applied to. The week is fixed-length and absent for a different reason - a duration is not usually stored counted in weeks - so it is left out until something asks for it rather than ruled out. Adding a unit is additive, and the lowering already knows the ratio.

Members are ordered from the finest unit to the coarsest, but no arithmetic meaning is attached to the underlying values - do not compare them to decide which unit is finer.