public bool ValidateEntity(EntityInfo entityInfo, List<EntityError> entityErrors) {
if (entityInfo.EntityState == EntityState.Deleted) return true;
bool isValid = true;
var entity = entityInfo.Entity;
var entityType = entity.GetType();
var entityTypeName = entityType.FullName;
var sType = _structuralTypeMap[entityTypeName];
var dataProperties = sType.dataProperties;
object[] keyValues = null;
foreach (var dp in sType.dataProperties) {
if (dp.validators == null) continue;
if (dp.propertyInfo == null) {
dp.propertyInfo = entityType.GetProperty(dp.name); // try converting from camelCase?
if (dp.propertyInfo == null) continue;
}
var value = dp.propertyInfo.GetValue(entity, null);
foreach (var validator in dp.validators) {
var errorMessage = validator.Validate(value);
if (errorMessage != null) {
if (keyValues == null) keyValues = _contextProvider.GetKeyValues(entityInfo);
entityErrors.Add(new EntityError() {
EntityTypeName = entityTypeName,
ErrorMessage = errorMessage,
ErrorName = "ValidationError",
KeyValues = keyValues,
PropertyName = dp.name
});
isValid = false;
}
}
}
return isValid;
}