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


































