Table of Contents

Class DurationAttribute

Namespace
LinqToDB.Mapping
Assembly
linq2db.dll

Declares that a TimeSpan column stores a duration, and in which unit.

[AttributeUsage(AttributeTargets.Property|AttributeTargets.Field, AllowMultiple = true, Inherited = true)]
public class DurationAttribute : MappingAttribute, _Attribute
Inheritance
object
DurationAttribute
Implements
Inherited Members
Extension Methods

Examples

[Column(DataType = DataType.Int64), Duration(DurationUnit.Second)]
public TimeSpan Elapsed { get; set; }

Remarks

Without this attribute (or the equivalent fluent or mapping schema configuration) a TimeSpan column keeps its existing meaning, which is provider-defined and is a time of day rather than a duration on providers that map TimeSpan to a TIME column. Duration semantics are opt-in precisely so that existing mappings are not silently reinterpreted.

The unit is what makes translation possible: a BIGINT column alone does not say whether it holds ticks or seconds, and guessing wrong is a silent factor-of-10000000 error.

Applying this attribute to a class or interface has no effect.

Constructors

DurationAttribute(DurationUnit)

Creates attribute instance.

public DurationAttribute(DurationUnit unit)

Parameters

unit DurationUnit

Unit in which the duration is stored.

Properties

Unit

Gets or sets the unit in which the duration is stored in the column.

public DurationUnit Unit { get; set; }

Property Value

DurationUnit

Methods

GetObjectID()

Returns mapping attribute id, based on all attribute options.

public override string GetObjectID()

Returns

string