Skip to content

Mapping Attributes

StrutTower edited this page Jul 3, 2024 · 2 revisions

When using the Property Name method for initializing a repository, attributes can be used on the class and properties to configure the database mapping.

[TableName]

The TableNameAttribute can be used to manually set the name of the database table if the name doesn't match the class name

Placement: Class

Example:

[TableName("databaseTableName")]
public class Person {

[Autonumber]

The AutonumberAttribute is used to map a property as a primary key with autonumber/autoincrement

Placement: Property

Example:

[Autonumber]
public int ID { get; set; }

[KeyMap]

The KeyMapAttribute is use to map a property as a primary key. Similar to [Key] in EntityFramework.

Placement: Property

Example:

[KeyMap]
public int ID { get; set; }

[ColumnMap]

The ColumnMapAttribute is use to set a column name that is different from the property name. Similar to [Column] in EntityFramework.

Placement: Property

Example:

[ColumnMap("Active")]
public bool IsActive { get; set; }

[SkipMapping]

The SkipMappingAttribute is used to prevent mapping a property to a database column. Use this if you have an extra property that doesn't match any database column. Similar to [NotMapped] in EntityFramework.

Placement: Property

Example:

[SkipMapping]
public string PropertyWithoutDatabaseColumn { get; set; }

Clone this wiki locally