Introducing Data Annotations
Data Annotations consists in decorating entities and their properties with some attributes from the System.ComponentModel.DataAnnotations
and System.ComponentModel.Data-Annotations.Schema
namespaces (from the System.ComponentModel.DataAnnotations.dll assembly, which is automatically referenced when you create a Code First–based model). You already saw a particular usage of data annotations when talking about data validation previously, but you can also provide additional information to types, not just validation rules. The following code demonstrates how to rewrite the Book
entity using data annotations:
Imports System.ComponentModel.DataAnnotationsImports System.ComponentModel.DataAnnotations.Schema ...
Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.