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
Uses attributes to declare expected input and validate binding models in minimal APIs, Razor Pages, and MVC.
How deep it goes
Explains common attributes, validation execution, a simple-parameter limitation, and alternatives for cross-property rules.
Examples
Uses a user model with name, email, and phone fields and a rule requiring at least one contact method.
What you can do after
Apply DataAnnotations with MinimalApis.Extensions to validate minimal API input and handle invalid requests.

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

Questions about dataannotations attribute

What is dataannotations attribute?

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

Which Manning books explain dataannotations attribute?

ASP.NET Core in Action, 3e and Building Web APIs with ASP.NET Core.

What is the difference between dataannotations attribute and FluentValidation?

A DataAnnotations attribute is a .NET attribute that declares metadata or validation rules for types, members, and data-model elements. FluentValidation is a .NET validation library that defines object validation rules with a fluent programming interface.

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.