Data Annotations Attributes

Configuration enables you to override EF Core's default behaviour. Configuration can be applied in two ways, using the Fluent API, and through DataAnnotation attributes.

Attributes are a kind of tag that you can place on a class or property to specify metadata about that class or property. Entity Framework Core makes use of attributes defined in the System.ComponentModel.DataAnnotations.Schema and System.ComponentModel.DataAnnotations namespaces.

System.ComponentModel.DataAnnotations.Schema attributes

Table The database table and/or schema that a class is mapped to.
Column The database column that a property is mapped to.
ForeignKey Specifies the property is used as a foreign key in a relationship.
DatabaseGenerated Specifies how the database generates values for a property.
NotMapped Applied to properties or classes that are to be excluded from database mapping.
InverseProperty |Specifies the inverse of a navigation property
ComplexType Denotes that the class is a complex type. *Not currently implemented in EF Core.

System.ComponentModel.Annotations attributes

Key Identifies one or more properties as a Key
Timestamp Specifies the data type of the database column as rowversion
ConcurrencyCheck Specifies that the property is included in concurrency checks
Required Specifies that the property's value is required
MaxLength Sets the maximum allowed length of the property value (string or array)
StringLength Sets the maximum allowed length of the property value (string or array)

Created:
Last updated: 14/03/2017 16:33:43
Proficiency Level: Beginner