dotnet/efcore · error · InvalidOperationException
The property ' . ' could not be found. Ensure that the…
Error message
The property '{1_entityType}.{0_property}' could not be found. Ensure that the property exists and has been included in the model. What it means
StoredProcedureBuilder.CreatePropertyBuilder (internal) searches the entity type and its derived types' declared properties for a name. If nothing matches, it throws CoreStrings.PropertyNotFound. This fires when a stored-procedure mapping references a property name that is not declared on the entity or any derived type.
Solutions
- Use the correct property name declared on the entity (or inherited from a base in the hierarchy).
- Prefer the lambda overload (e.g. sp.HasParameter(e => e.Name)) for compile-time safety.
- If the property should exist, ensure it is not ignored and is mapped on this entity type.
Example fix
// before
modelBuilder.Entity<Order>()
.InsertStoredProcedure("InsertOrder", sp => sp.HasParameter("CustId")); // real name is 'CustomerId' -> [455]
// after
modelBuilder.Entity<Order>()
.InsertStoredProcedure("InsertOrder", sp => sp.HasParameter(o => o.CustomerId)); Defensive patterns
Strategy: type-guard
Validate before calling
// Verify the property exists on the entity (or derived types) before configuring the sproc.
var et = entityTypeBuilder.Metadata;
var found = et.FindProperty(propertyName)
?? et.GetDerivedTypes().SelectMany(d => d.GetDeclaredProperties()).FirstOrDefault(p => p.Name == propertyName);
if (found is null)
throw new ArgumentException($"Property '{propertyName}' not found on {et.DisplayName()}."); Type guard
static bool EntityOrDerivedHasProperty(IEntityType et, string name)
=> et.FindProperty(name) is not null
|| et.GetDerivedTypes().SelectMany(d => d.GetDeclaredProperties()).Any(p => p.Name == name); Prevention
- Prefer lambda-based sproc mapping overloads to avoid string typos.
- Keep sproc string mappings in sync with property renames.
- Add a model-build unit test to catch missing-property errors early.
When it happens
Trigger: Configuring an entity's stored procedure (InsertStoredProcedure/UpdateStoredProcedure/DeleteStoredProcedure) and passing a string property name that does not exist on the entity type or its derived types — e.g. .HasParameter("Nonexistent"), a result-column binding, or an original-value binding with a wrong name.
Common situations: Renamed properties with stale sproc string mappings; typos; properties that exist only on a sibling (not derived) type; properties ignored from the model.
Related errors
- The property ' . ' could not be found. Ensure that the…
- Table name must be specified to configure a table-specific…
- Table name must be specified to configure a table-specific…
- A rows affected parameter, result column or return value…
- Both ' ' and ' ' are explicitly mapped to the stored…
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/b8c85d244ab01494.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Relational/Metadata/Builders/StoredProcedureBuilder.cs:220
}
/// <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>
[EntityFrameworkInternal]
protected virtual PropertyBuilder CreatePropertyBuilder(string propertyName)
{
var entityType = EntityTypeBuilder.Metadata;
var property = entityType.FindProperty(propertyName);
property ??= entityType.GetDerivedTypes().SelectMany(et => et.GetDeclaredProperties())
.FirstOrDefault(p => p.Name == propertyName);
if (property == null)
{
throw new InvalidOperationException(CoreStrings.PropertyNotFound(propertyName, entityType.DisplayName()));
}
#pragma warning disable EF1001 // Internal EF Core API usage.
return new ModelBuilder(entityType.Model)
#pragma warning restore EF1001 // Internal EF Core API usage.
.Entity(property.DeclaringType.Name)
.Property(property.ClrType, propertyName);
}
/// <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>
[EntityFrameworkInternal]
protected virtual PropertyBuilder CreatePropertyBuilder<TDerivedEntity, TProperty>(
Expression<Func<TDerivedEntity, TProperty>> propertyExpression)View on GitHub (pinned to 3a2006ef56)