liveBook · Manning

Missing value

As explained in Pro ASP.NET Core 7, Tenth Edition

A null value represents the absence of an object reference or other value in a context where null is permitted.

A null value represents the absence of an object reference or another value where null is permitted. In ASP.NET Core code, null appears in models, collections, database relationships, and serialized responses. section 5.0 section 5.1.3

Handle missing values by choosing where absence is valid and how it should cross application boundaries:

  • Use nullable types when a property may have no value, such as a nullable decimal price. section 5.0 section 5.1.3
  • Use deliberate null entries to exercise application behavior and expose editor warnings before applying null-state analysis. section 5.1.3
  • Omit null properties from JSON by projecting only required fields or configuring JsonIgnoreCondition.WhenWritingNull. section 19.5.6
  • Break circular references before serialization by setting selected related properties to null. section 20.2.1

Removing unavailable API data

A product response can contain category and supplier properties whose values are always null when related data was not loaded. Projecting ProductId, Name, Price, CategoryId, and SupplierId removes those misleading properties. Alternatively, applying [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] to Supplier preserves the model while omitting that property from JSON. section 19.5.6

Listing 5.3 The contents of the Product.cs file in the Models folder
namespace LanguageFeatures.Models {
   public class Product {

       public string Name { get; set; }
       public decimal? Price { get; set; }

       public static Product[] GetProducts() {

           Product kayak = new Product { 
               Name = "Kayak", Price = 275M 
           };

           Product lifejacket = new Product { 
               Name = "Lifejacket", Price = 48.95M 
           };

           return new Product[] { kayak, lifejacket, null };
       }
   }
}

Inspect the Product model and its deliberately null array element alongside a nullable Price property. section 5.1.3

How Pro ASP.NET Core 7, Tenth Edition covers it

How deep it goes
Defines nullable values and demonstrates model, serialization, and reference-handling techniques without detailing null-state analysis internals.
Examples
Demonstrates a null Product array element, nullable Price, omitted API properties, and nulling Supplier references before serialization.
What you can do after
Apply it via nullable types, response projection, JsonIgnoreCondition.WhenWritingNull, and reference cleanup before JSON serialization.
How it connects
Connects null with nullable types, null-state analysis, JSON serialization, Entity Framework Core navigation properties, and circular references.

Also explained in

Compare how 35 books explain missing value →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro ASP.NET Core 7, Tenth Edition. The section links point to the parts of the book it draws on.