liveBook · Manning

Dataannotations attribute

A DataAnnotations attribute is a .NET attribute that declares metadata or validation rules for types, members, and data-model elements.

How 2 Manning books explain it

ASP.NET Core in Action, 3e

DataAnnotations is the .NET attribute-based framework for declaring metadata and validation rules on types and their members.

How it is used
Declares expected user input on binding models for validation in minimal APIs, Razor Pages, and MVC.
How deep it goes
Works through property-level rules and framework validation behavior, including filter setup and a simple-parameter limitation.
Examples
Uses a user-details model with required names, email and phone formats, a display name, and an optional phone number.
What you can do after
Apply it via DataAnnotations attributes on binding models and arrange server-side handling appropriate to the ASP.NET Core framework.

Read how ASP.NET Core in Action, 3e explains dataannotations attribute →

Building Web APIs with ASP.NET Core

A data annotation is an attribute-based Entity Framework Core configuration mechanism that adds metadata to entity classes and their members.

How it is used
Uses attributes to configure EF Core entities and constrain input accepted by an ASP.NET Core API.
How deep it goes
Works through entity and endpoint attributes, then distinguishes configuration precedence and delegates composite-key configuration to Fluent API.
Examples
Shows BoardGame entity attributes and a [Range(1, 100)] page-size limit on GET /BoardGames.
What you can do after
Apply attributes to configure individual EF Core entity settings and reject out-of-range API inputs without manual checks.

Read how Building Web APIs with ASP.NET Core explains dataannotations attribute →

Related concepts

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.