dotnet/efcore · error · DbUpdateException
Required properties '{requiredProperties}' are missing for t
Error message
Required properties '{requiredProperties}' are missing for the instance of entity type '{entityType}' with the key value '{keyValue}'. What it means
During Create/Update the InMemory store detected that one or more non-nullable properties had a null value, and EnableSensitiveDataLogging() is on, so the entity key value is included in the message (InMemoryTable.cs:397-402). This is a DbUpdateException, not a concurrency error.
Source
Thrown at src/EFCore.InMemory/Storage/Internal/InMemoryTable.cs:397
}
private static bool IsNullable(IProperty property)
=> property.IsNullable
|| (property.DeclaringType is IComplexType complexType
&& IsNullable(complexType.ComplexProperty));
private static bool IsNullable(IComplexProperty property)
=> 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 thatView on GitHub (pinned to dbf9771522)
Solutions
- Set the required property to a non-null value before calling SaveChanges.
- If nulls are legitimately possible, make the property nullable in the model.
- Provide a value generator or HasDefaultValue so the store can supply a value.
Example fix
// before
db.Add(new Order { CustomerId = 1 }); // Total (required) missing
db.SaveChanges();
// after
db.Add(new Order { CustomerId = 1, Total = 0m });
db.SaveChanges(); Defensive patterns
Strategy: validation
Validate before calling
// Before SaveChanges, verify required (non-nullable) scalar properties are set:
foreach (var entry in ctx.ChangeTracker.Entries())
{
foreach (var prop in entry.Metadata.GetProperties())
{
if (!prop.IsNullable
&& entry.CurrentValues[prop] is null
&& prop.ValueGenerated == ValueGenerated.Never)
{
throw new InvalidOperationException($"{entry.Entity.GetType().Name}.{prop.Name} is required but null.");
}
}
} Try / catch
try
{
ctx.SaveChanges();
}
catch (DbUpdateException ex) when (ex.Message.Contains("Required properties"))
{
// identify and set the null required property, then retry
} Prevention
- Validate required properties in domain code or via data annotations before SaveChanges.
- Use HasDefaultValue or value generators for store-supplied required values.
- EnableSensitiveDataLogging in dev/test to quickly identify the offending entity and key.
When it happens
Trigger: Calling SaveChanges on an entity (insert or update) where a property declared as non-nullable (IsNullable == false, not a nullable complex type) resolves to null at store time, with EnableSensitiveDataLogging enabled.
Common situations: Forgetting to set a required property, a value converter returning null, or a computed/default value not being applied. Sensitive logging variant appears in dev/test where EnableSensitiveDataLogging is configured.
Related errors
- Required properties '{requiredProperties}' are missing for t
- The property '{1_entityType}.{0_property}' contains null, bu
- The property '{property}' of the argument '{argument}' canno
- The context class name '{contextClassName}' is not a valid C
- The LINQ expression '{expression}' could not be translated.
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/499e725b0ad1e8a0.
Report an issue: GitHub.