dotnet/efcore · error · InvalidOperationException
The property '{property}' on type '{type}' is mapped to a JS
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
ValidateAutoLoaded (RelationalModelValidator.cs:208-213) throws when a property belonging to a JSON-mapped entity/complex type is configured as NOT auto-loaded. JSON-mapped entities are stored as a single JSON document and always loaded atomically as a unit, so marking an individual property inside that document as lazy/explicitly-not-auto-loaded is meaningless and rejected at model validation time.
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 dbf9771522)
Solutions
- Remove the IsAutoLoaded(false)/AutoLoad configuration from properties inside JSON-mapped types.
- If you need conditional loading of a sub-part, split that part into its own entity/table instead of a JSON column.
- Scope any 'disable auto-load' convention to exclude types where IsMappedToJson() is true.
Example fix
// before
modelBuilder.Entity<Order>().OwnsOne(o => o.Address, a =>
{
a.ToJson("AddressJson");
a.Property(p => p.Street).IsAutoLoaded(false); // throws at validation
});
// after - drop the auto-load config inside JSON types
modelBuilder.Entity<Order>().OwnsOne(o => o.Address, a =>
{
a.ToJson("AddressJson");
}); Defensive patterns
Strategy: validation
Validate before calling
// Pre-validate: no JSON-mapped type should have a not-auto-loaded property.
foreach (var type in context.Model.GetEntityTypes().Cast<ITypeBase>()
.Concat(context.Model.GetEntityTypes().SelectMany(e => e.GetComplexTypes())))
{
if (type.IsMappedToJson())
{
foreach (var p in type.GetProperties().Where(p => !p.IsAutoLoaded))
{
// will throw at validation - remove this config.
}
}
} Prevention
- Never apply IsAutoLoaded(false) to properties inside ToJson()-mapped types.
- Scope global auto-load conventions to exclude IsMappedToJson() types.
- Treat JSON-mapped entities as atomic load units.
When it happens
Trigger: Configuring a property inside a JSON-mapped owned/complex type (ToJson()) with IsAutoLoaded(false), or applying an AutoLoad(false) annotation to such a property. Triggered during model validation when the context is first used.
Common situations: Copying eager/lazy-loading config onto owned JSON entities by mistake; applying a blanket 'disable auto-load' convention that also hits JSON-owned properties; mixing classic navigation auto-load semantics with JSON columns.
Related errors
- The key {keyProperties} on the entity type '{entityType}' ca
- The optional complex property '{type}.{property}' is mapped
- Complex property '{complexProperty}' cannot have both a JSON
- Complex property '{complexProperty}' cannot use 'HasJsonProp
- Complex property '{complexProperty}' is mapped to JSON but i
AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06).
Data as JSON: /api/errors/008a70b08addcf8c.
Report an issue: GitHub.