Class ColumnAttribute
Configures mapping of mapping class member to database column. Could be applied directly to a property or field or to mapping class/interface. In latter case you should specify member name using MemberName property.
[AttributeUsage(AttributeTargets.Class|AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Interface, AllowMultiple = true, Inherited = true)]
public class ColumnAttribute : MappingAttribute, _Attribute
- Inheritance
-
ColumnAttribute
- Implements
- Derived
- Inherited Members
- Extension Methods
Constructors
ColumnAttribute()
Creates attribute instance.
public ColumnAttribute()
ColumnAttribute(string)
Creates attribute instance.
public ColumnAttribute(string columnName)
Parameters
columnName
stringDatabase column name.
ColumnAttribute(string, string)
Creates attribute instance.
public ColumnAttribute(string columnName, string memberName)
Parameters
columnName
stringDatabase column name.
memberName
stringName of mapped member. See MemberName for more details.
Properties
CanBeNull
Gets or sets whether a column can contain NULL
values.
public bool CanBeNull { get; set; }
Property Value
CreateFormat
Custom template for column definition in create table SQL expression, generated using CreateTable<T>(IDataContext, string?, string?, string?, string?, string?, DefaultNullable, string?, TableOptions) methods. Template accepts following string parameters:
- {0} - column name;
- {1} - column type;
- {2} - NULL specifier;
- {3} - identity specification.
public string? CreateFormat { get; set; }
Property Value
DataType
Gets or sets linq2db type for column. Default value: default type, defined for member type in mapping schema.
public DataType DataType { get; set; }
Property Value
DbType
Gets or sets the name of the database column type. Default value: default type, defined for member type in mapping schema.
public string? DbType { get; set; }
Property Value
IsColumn
Gets or sets flag that tells that current member should be included into mapping.
Use NonColumnAttribute instead as a shorthand.
Default value: true
.
public bool IsColumn { get; set; }
Property Value
IsDiscriminator
Gets or sets whether a column contains a discriminator value for a LINQ to DB inheritance hierarchy.
InheritanceMappingAttribute for more details.
Default value: false
.
public bool IsDiscriminator { get; set; }
Property Value
IsIdentity
Gets or sets whether a column contains values that the database auto-generates. Also see IdentityAttribute.
public bool IsIdentity { get; set; }
Property Value
IsPrimaryKey
Gets or sets whether this class member represents a column that is part or all of the primary key of the table. Also see PrimaryKeyAttribute.
public bool IsPrimaryKey { get; set; }
Property Value
Length
Gets or sets the length of the database column. Default value: value, defined for member type in mapping schema.
public int Length { get; set; }
Property Value
MemberName
Gets or sets the name of mapped member. When applied to class or interface, should contain name of property of field.
If column mapped to a property or field of composite object, MemberName should contain a path to that
member using dot as separator.
public class Address
{
public string City { get; set; }
public string Street { get; set; }
public int Building { get; set; }
}
[Column("city", "Residence.City")]
[Column("user_name", "Name")]
public class User
{
public string Name;
[Column("street", ".Street")]
[Column("building_number", MemberName = ".Building")]
public Address Residence { get; set; }
}</code></pre></example>
public string? MemberName { get; set; }
Property Value
Name
Gets or sets the name of a column in database. If not specified, member name will be used.
public string? Name { get; set; }
Property Value
Order
Specifies the order of the field in table creation. Positive values first (ascending), then unspecified (arbitrary), then negative values (ascending).
public int Order { get; set; }
Property Value
Remarks
Ordering performed in SqlTable constructor.
Precision
Gets or sets the precision of the database column. Default value: value, defined for member type in mapping schema.
public int Precision { get; set; }
Property Value
PrimaryKeyOrder
Gets or sets the Primary Key order. See Order for more details.
public int PrimaryKeyOrder { get; set; }
Property Value
Scale
Gets or sets the Scale of the database column. Default value: value, defined for member type in mapping schema.
public int Scale { get; set; }
Property Value
SkipOnEntityFetch
Gets or sets whether a column must be explicitly defined in a Select statement to be fetched. If true
, a "SELECT *"-ish statement won't retrieve this column.
Default value: false
.
public bool SkipOnEntityFetch { get; set; }
Property Value
SkipOnInsert
Gets or sets whether a column is insertable. This flag will affect only insert operations with implicit columns specification like Insert<T>(IDataContext, T, string?, string?, string?, string?, TableOptions) method and will be ignored when user explicitly specifies value for this column.
public bool SkipOnInsert { get; set; }
Property Value
SkipOnUpdate
Gets or sets whether a column is updatable. This flag will affect only update operations with implicit columns specification like Update<T>(IDataContext, T, string?, string?, string?, string?, TableOptions) method and will be ignored when user explicitly specifies value for this column.
public bool SkipOnUpdate { get; set; }
Property Value
Storage
Gets or sets a storage property or field to hold the value from a column. Could be usefull e.g. in combination of private storage field and getter-only mapping property.
public string? Storage { get; set; }
Property Value
Methods
GetObjectID()
Returns mapping attribute id, based on all attribute options.
public override string GetObjectID()