{"record":{"id":"f6cc36e01eed0420","repo":"dotnet/efcore","slug":"required-properties-requiredproperties-are-mis-f6cc36","errorCode":null,"errorMessage":"Required properties '{requiredProperties}' are missing for the instance of entity type '{entityType}'. Consider using 'DbContextOptionsBuilder.EnableSensitiveDataLogging' to see the entity key value.","messagePattern":"Required properties '(.+?)' are missing for the instance of entity type '(.+?)'\\. Consider using 'DbContextOptionsBuilder\\.EnableSensitiveDataLogging' to see the entity key value\\.","errorType":"exception","errorClass":"DbUpdateException","httpStatus":null,"severity":"error","filePath":"src/EFCore.InMemory/Storage/Internal/InMemoryTable.cs","lineNumber":405,"sourceCode":"        => property.IsNullable\n            || (property.DeclaringType is IComplexType complexType\n                && IsNullable(complexType.ComplexProperty));\n\n    private void ThrowNullabilityErrorException(\n        IUpdateEntry entry,\n        IList<IProperty> nullabilityErrors)\n    {\n        if (_sensitiveLoggingEnabled)\n        {\n            throw new DbUpdateException(\n                InMemoryStrings.NullabilityErrorExceptionSensitive(\n                    nullabilityErrors.Format(),\n                    entry.EntityType.DisplayName(),\n                    entry.BuildCurrentValuesString(entry.EntityType.FindPrimaryKey()!.Properties)),\n                [entry]);\n        }\n\n        throw new DbUpdateException(\n            InMemoryStrings.NullabilityErrorException(\n                nullabilityErrors.Format(),\n                entry.EntityType.DisplayName()),\n            [entry]);\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    protected virtual void ThrowUpdateConcurrencyException(\n        IUpdateEntry entry,\n        Dictionary<IProperty, object?> concurrencyConflicts,\n        IDiagnosticsLogger<DbLoggerCategory.Update> updateLogger)\n    {\n        var entries = new[] { entry };","sourceCodeStart":387,"sourceCodeEnd":423,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.InMemory/Storage/Internal/InMemoryTable.cs#L387-L423","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before — cannot identify which entity has null required properties\nctx.SaveChanges(); // throws without key value\n\n// after — enable sensitive logging in debug to diagnose\noptionsBuilder\n    .UseInMemoryDatabase(\"db\")\n    .EnableSensitiveDataLogging(); // now error includes key value\n// then fix the entity that produced the null","handlingStrategy":"validation","validationCode":"// Before SaveChanges, validate that all required properties are non-null.\n// This pre-empts the InMemory nullability check and gives better diagnostics.\nstatic void ValidateRequiredProperties(DbContext context)\n{\n    foreach (var entry in context.ChangeTracker.Entries()\n        .Where(e => e.State is EntityState.Added or EntityState.Modified))\n    {\n        var nullProps = entry.Metadata.GetProperties()\n            .Where(p => !p.IsNullable && entry.CurrentValues[p] is null)\n            .Select(p => p.Name)\n            .ToList();\n        if (nullProps.Count > 0)\n        {\n            throw new ValidationException(\n                $\"{entry.EntityType.DisplayName()} key={entry.BuildCurrentValuesString(\n                    entry.Metadata.FindPrimaryKey()!.Properties)} \" +\n                $\"missing required: {string.Join(\", \", nullProps)}\");\n        }\n    }\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    context.SaveChanges();\n}\ncatch (DbUpdateException ex) when (ex.Message.Contains(\"Required properties\"))\n{\n    // Temporarily enable sensitive data logging to identify the entity, then fix\n    logger.LogError(ex, \"Required properties missing. Enable sensitive data logging to identify the entity.\");\n    throw;\n}","preventionTips":["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."],"tags":["efcore","inmemory","validation","required-properties","savechanges"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}