liveBook · Manning

Plain old CLR object

As explained in ASP.NET Core in Action, 3e

A plain old CLR object is an ordinary .NET object that does not depend on a specialized framework base type or programming model.

A plain old CLR object (POCO) is an ordinary .NET class that does not depend on a specialized framework base class or programming model. Framework features can populate, serialize, or map these objects while application code works with familiar properties and collections. section 7.0 section 12.2.2

POCOs appear in several common framework roles:

  • Model binding populates POCO properties from values in an HTTP request and passes the resulting object to an endpoint handler. section 7.0
  • The IOptions<T> binder creates nonabstract POCO options classes with public parameterless constructors, then binds eligible public properties. section 10.3.3
  • EF Core uses POCO classes as entities and applies conventions such as Id-suffixed primary keys and foreign-key relationships. section 12.2.2
  • Minimal API handlers can return POCOs, which are serialized as JSON in a successful response. section 5.3

Recipe entities

A Recipe class with RecipeId, Name, and an ICollection<Ingredient> can remain an ordinary C# class while EF Core interprets its properties as database keys and relationships. section 12.2.2

Listing 12.2 Defining the EF Core entity classes
public class Recipe
{
    public int RecipeId { get; set; }
    public required string Name { get; set; }
    public TimeSpan TimeToCook { get; set; }
    public bool IsDeleted { get; set; }
    public required string Method { get; set; }
    public required ICollection<Ingredient> Ingredients { get; set; }   #1
}
public class Ingredient
{
    public int IngredientId { get; set; }
    public int RecipeId { get; set; }
    public required string Name { get; set; }
    public decimal Quantity { get; set; }
    public required string Unit { get; set; }
}

Inspect the Recipe and Ingredient classes to see how simple properties and a collection express an EF Core data model. section 12.2.2

How ASP.NET Core in Action, 3e covers it

How deep it goes
Defines POCOs and explains binding conventions, but stops short of detailing every EF Core mapping convention.
Examples
Uses BindableOptions, Recipe, Ingredient, Person, and Fruit as concrete POCO examples.
What you can do after
Apply it via model binding, IOptions<T>, EF Core entities, and minimal API JSON responses.
How it connects
Connects POCOs with model binding, the options pattern, Entity Framework Core, minimal APIs, JSON serialization, and relational keys.

Also explained in

Compare how 2 books explain plain old CLR object →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.