dotnet/efcore · error · DbUpdateException
Required properties ' ' are missing for the instance of…
Error message
Required properties '{requiredProperties}' are missing for the instance of entity type '{entityType}'. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the entity key value. What it means
InMemoryTable.ThrowNullabilityErrorException is called when saving an entity instance that has one or more required (non-nullable) properties set to null. With sensitive data logging NOT enabled (_sensitiveLoggingEnabled is false), the error omits the key value for privacy and instead advises calling EnableSensitiveDataLogging to see it. A DbUpdateException is thrown with the entry attached.
Solutions
- Temporarily enable EnableSensitiveDataLogging() in your DbContext options (debug/dev only) to see the key value and identify the offending entity, then fix the data.
- Ensure every required property on the entity is assigned a non-null value before Add/SaveChanges.
- If null is a valid state, configure the property as nullable (IsRequired(false) or a nullable CLR type).
- Add validation in your entity constructor or factory method so required properties cannot be omitted.
Example fix
// before — cannot identify which entity has null required properties
ctx.SaveChanges(); // throws without key value
// after — enable sensitive logging in debug to diagnose
optionsBuilder
.UseInMemoryDatabase("db")
.EnableSensitiveDataLogging(); // now error includes key value
// then fix the entity that produced the null Defensive patterns
Strategy: validation
Validate before calling
// Before SaveChanges, validate that all required properties are non-null.
// This pre-empts the InMemory nullability check and gives better diagnostics.
static void ValidateRequiredProperties(DbContext context)
{
foreach (var entry in context.ChangeTracker.Entries()
.Where(e => e.State is EntityState.Added or EntityState.Modified))
{
var nullProps = entry.Metadata.GetProperties()
.Where(p => !p.IsNullable && entry.CurrentValues[p] is null)
.Select(p => p.Name)
.ToList();
if (nullProps.Count > 0)
{
throw new ValidationException(
$"{entry.EntityType.DisplayName()} key={entry.BuildCurrentValuesString(
entry.Metadata.FindPrimaryKey()!.Properties)} " +
$"missing required: {string.Join(", ", nullProps)}");
}
}
} Try / catch
try
{
context.SaveChanges();
}
catch (DbUpdateException ex) when (ex.Message.Contains("Required properties"))
{
// Temporarily enable sensitive data logging to identify the entity, then fix
logger.LogError(ex, "Required properties missing. Enable sensitive data logging to identify the entity.");
throw;
} Prevention
- Always set required properties before calling Add() on an entity.
- Add a pre-save validation pass over ChangeTracker entries.
- Enable EnableSensitiveDataLogging() in debug/dev environments to see key values in errors.
- Use nullable reference types to get compile-time warnings on potential null assignments.
When it happens
Trigger: Calling SaveChanges or SaveChangesAsync when at least one tracked entity instance has a null value for a property configured as required (non-nullable), without EnableSensitiveDataLogging enabled. The InMemory store validates nullability before persisting and surfaces the offending property names but not the key value.
Common situations: Production or default configurations where sensitive data logging is off. Forgetting to set a required property before Add. Changing a property to required while existing insert code paths still produce nulls. The error lists which properties are null but not which entity row, making diagnosis harder.
Related errors
- Required properties ' ' are missing for the instance of…
- A synchronous store management operation was performed and…
- 'DefaultIfEmpty' cannot be applied after a client-evaluated…
- The LINQ expression ' ' could not be translated. Either…
- The LINQ expression ' ' could not be translated. Additional…
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/f6cc36e01eed0420.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.InMemory/Storage/Internal/InMemoryTable.cs:405
=> property.IsNullable
|| (property.DeclaringType is IComplexType complexType
&& IsNullable(complexType.ComplexProperty));
private void ThrowNullabilityErrorException(
IUpdateEntry entry,
IList<IProperty> nullabilityErrors)
{
if (_sensitiveLoggingEnabled)
{
throw new DbUpdateException(
InMemoryStrings.NullabilityErrorExceptionSensitive(
nullabilityErrors.Format(),
entry.EntityType.DisplayName(),
entry.BuildCurrentValuesString(entry.EntityType.FindPrimaryKey()!.Properties)),
[entry]);
}
throw new DbUpdateException(
InMemoryStrings.NullabilityErrorException(
nullabilityErrors.Format(),
entry.EntityType.DisplayName()),
[entry]);
}
/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
/// the same compatibility standards as public APIs. It may be changed or removed without notice in
/// any release. You should only use it directly in your code with extreme caution and knowing that
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
protected virtual void ThrowUpdateConcurrencyException(
IUpdateEntry entry,
Dictionary<IProperty, object?> concurrencyConflicts,
IDiagnosticsLogger<DbLoggerCategory.Update> updateLogger)
{
var entries = new[] { entry };View on GitHub (pinned to 3a2006ef56)