aspnetboilerplate/aspnetboilerplate · error · KeyNotFoundException
The property was not found in entity
Error message
The property {propertyInfo.Name} was not found in {mainMap.EntityType.Name} entity What it means
GetPropertyMap throws KeyNotFoundException when the supplied MemberInfo is not among the properties mapped on the main entity's ClassMapper. It is used while resolving left/right property maps for reference (join) mappings, so a property that participates in a reference but isn't mapped on the entity triggers this.
Solutions
- Add the missing property to the entity's ClassMapper (ensure it is mapped, not Ignored)
- Verify the MemberInfo/name used in the reference configuration belongs to mainMap.EntityType
- Check auto-mapping conventions (accessibility, get/set) so the property is discovered
- Rebuild mappings if a cached map predates an entity change
Example fix
// before Map(x => x.CustomerId).Ignore(); // not mapped // reference config references x => x.CustomerId -> throws // after Map(x => x.CustomerId); // mapped, resolvable in reference config
Defensive patterns
Strategy: validation
Validate before calling
bool mapped = mainMap.Properties.Any(p => p.MemberInfo == propertyInfo);
if (!mapped) throw new InvalidOperationException($"{propertyInfo.Name} is not mapped on {mainMap.EntityType.Name}"); Type guard
bool IsMappedOn(IClassMapper map, MemberInfo mi) => map?.Properties?.Any(p => p.MemberInfo == mi) == true;
Try / catch
try { BuildReferenceSql(...); } catch (KeyNotFoundException ex) when (ex.Message.Contains("was not found in")) { throw new MappingException("Reference configuration points to an unmapped property", ex); } Prevention
- Keep every property used in reference/join configs mapped in the ClassMapper
- After renaming entity properties, update reference configurations and re-run mapping tests
- Avoid Ignoring properties that participate in joins
When it happens
Trigger: Building a reference mapping where the referenced property name/MemberInfo belongs to a different entity, or the property is not registered in the ClassMapper (e.g. it's Ignore()d or auto-mapping skipped it).
Common situations: Typo or renamed property in a reference configuration; property excluded by MapConvention (private, no setter) but still referenced in a join config; mapping definitions stale after entity refactoring.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- was not found for
- Map was not found for
- No columns were mapped.
- Table column not set.
- TriggerIdentity generator cannot be used with multi-column…
AI-assisted analysis of aspnetboilerplate/aspnetboilerplate@2323c13a15 (2026-09-08).
Data as JSON: /api/errors/e878bbb171ab7d20.
Report an issue: GitHub.
Appendix: source
Thrown at src/Abp.Dapper/Dapper-Extensions/Sql/SqlGenerator.cs:331
var sql = new StringBuilder($"DELETE FROM {GetTableName(classMap)}");
sql.Append(" WHERE ").Append(predicate.GetSql(this, parameters, true));
return sql.ToString();
}
public virtual string IdentitySql(IClassMapper classMap)
{
return Configuration.Dialect.GetIdentitySql(GetTableName(classMap));
}
public virtual string GetReferenceKey(IMemberMap map)
{
return $"{map.ClassMapper.TableName}.{map.ColumnName}";
}
private static IMemberMap GetPropertyMap(IClassMapper mainMap, MemberInfo propertyInfo)
{
if (!mainMap.Properties.Any(p => p.MemberInfo == propertyInfo))
throw new KeyNotFoundException($"The property {propertyInfo.Name} was not found in {mainMap.EntityType.Name} entity");
return mainMap
.Properties
.Where(p => p.MemberInfo == propertyInfo)
.Select(propertyMap => propertyMap)
.Single();
}
private string GetJointTables(IClassMapper mainMap, Table table, IDictionary<string, object> parameters, IList<IReferenceMap> includedProperties = null)
{
if (parameters == null)
{
throw new ArgumentNullException(nameof(parameters), $"{nameof(parameters)} cannot be null.");
}
var result = new StringBuilder();
var joins = new StringBuilder();
var sql = new StringBuilder();
var parent = Tables.Single(t => t.Identity == table.ParentIdentity);View on GitHub (pinned to 2323c13a15)