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}'. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the entity key value.

What it means

Same nullability failure as 329 but with EnableSensitiveDataLogging OFF, so the key value is omitted and the message instead suggests enabling it to see the key (InMemoryTable.cs:405-409). A non-nullable property was null during Create/Update.

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 dbf9771522)

Solutions

  1. Set the required property to a non-null value before SaveChanges.
  2. Temporarily enable EnableSensitiveDataLogging() in a dev build to identify the offending entity/key (this switches the error to 329 which shows the key).
  3. Make the property nullable or provide a default value/generator.

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"))
{
    // enable EnableSensitiveDataLogging in dev to see the key, then set the property
}

Prevention

When it happens

Trigger: Saving an entity where a non-nullable property resolves to null, without EnableSensitiveDataLogging configured.

Common situations: Production/default config where sensitive data logging is disabled. Forgetting required fields or value converters yielding null.

Related errors


AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06). Data as JSON: /api/errors/f6cc36e01eed0420. Report an issue: GitHub.