dotnet/efcore · error · InvalidOperationException
The property ' ' on type ' ' is mapped to a JSON entity and…
Error message
The property '{property}' on type '{type}' is mapped to a JSON entity and cannot be configured as not auto-loaded. JSON-mapped entities are always loaded as a unit. What it means
RelationalModelValidator.ValidateAutoLoaded throws AutoLoadedJsonProperty when a property on a JSON-mapped entity type is configured as IsAutoLoaded(false). JSON entities are serialized/deserialized as a single unit, so individual properties cannot opt out of being loaded — the validator enforces this invariant at model finalization.
Solutions
- Remove IsAutoLoaded(false) from any property on a JSON-mapped entity type — the whole JSON document is always loaded.
- If granular loading is required, do not map the entity to JSON; flatten to columns or split into a separate non-JSON entity.
- Project only the needed fields in queries (Select) instead of trying to opt out at the model level.
Example fix
// before
modelBuilder.Entity<Order>()
.OwnsOne(o => o.Details, d =>
{
d.ToJson("details");
d.Property(p => p.BigNotes).IsAutoLoaded(false); // throws
});
// after — drop the IsAutoLoaded call; project instead if needed
modelBuilder.Entity<Order>()
.OwnsOne(o => o.Details, d => d.ToJson("details")); Defensive patterns
Strategy: validation
Validate before calling
foreach (var p in entityType.GetProperties())
if (entityType.IsMappedToJson() && !p.IsAutoLoaded)
throw new InvalidOperationException($"Property {p.Name} on JSON entity cannot be non-auto-loaded."); Type guard
static bool IsJsonPropertyOnJsonEntity(IProperty p) => p.DeclaringType.IsMappedToJson();
Prevention
- Do not call IsAutoLoaded(false) on properties of JSON-mapped entities.
- When migrating owned types to ToJson, audit and remove prior AutoLoaded(false) calls.
- Use query projection (Select) to limit fields read from JSON instead of model-level opt-out.
When it happens
Trigger: Calling property.IsAutoLoaded = false (or IsAutoLoaded(ConfigurationSource.Explicit).AutoLoaded(false)) on a property whose declaring entity type is mapped to JSON (entity.IsMappedToJson() is true via ToJson). The base validator allows it; the relational override adds the JSON check and throws.
Common situations: Configuring an owned JSON entity and trying to mark a large text property as lazy/non-auto-loaded to save bandwidth; migrating an owned-type configuration to ToJson and forgetting to remove the AutoLoaded(false) calls; bulk-applying AutoLoaded conventions to all properties including JSON ones.
Related errors
- Both properties ' ' and ' ' on entity type ' ' are mapped…
- Complex property ' ' cannot have both a JSON column name ('…
- Complex property ' ' cannot use 'HasJsonPropertyName()'…
- Complex property ' ' is mapped to JSON but its containing…
- Entity type ' ' has a split mapping and is an optional…
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/008a70b08addcf8c.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs:211
ValidatePropertyOverride(property, storeObjectOverride, logger);
}
}
ValidateBoolWithDefaults(property, logger);
}
/// <inheritdoc />
protected override void ValidateAutoLoaded(
IProperty property,
ITypeBase structuralType,
IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
{
base.ValidateAutoLoaded(property, structuralType, logger);
if (!property.IsAutoLoaded
&& structuralType.IsMappedToJson())
{
throw new InvalidOperationException(
RelationalStrings.AutoLoadedJsonProperty(property.Name, structuralType.DisplayName()));
}
}
/// <inheritdoc />
protected override void ValidateKey(
IKey key,
IDiagnosticsLogger<DbLoggerCategory.Model.Validation> logger)
{
base.ValidateKey(key, logger);
foreach (var property in key.Properties)
{
if (property.DeclaringType is IComplexType complexType
&& complexType.IsMappedToJson())
{
throw new InvalidOperationException(
RelationalStrings.KeyPropertyInJsonComplexType(View on GitHub (pinned to 3a2006ef56)