Class DataAnnotationsValidator
- Namespace
- Breeze.Persistence
- Assembly
- Breeze.Persistence.dll
Validates entities on the server with System.ComponentModel.DataAnnotations, turning any failures into the EntityError list a Breeze client expects.
public class DataAnnotationsValidator
- Inheritance
-
DataAnnotationsValidator
- Inherited Members
Constructors
DataAnnotationsValidator(PersistenceManager)
Create a new instance.
public DataAnnotationsValidator(PersistenceManager persistenceManager)
Parameters
persistenceManagerPersistenceManagerUsed for getting entity keys for building EntityError objects.
Methods
AddDescriptor(Type, Type)
Attach a metadata (buddy) class to an entity type, so annotations declared on it are honoured.
public static void AddDescriptor(Type entityType, Type metadataType)
Parameters
entityTypeTypeThe entity type being validated.
metadataTypeTypeThe class carrying the annotations for it.
Remarks
Use this where the entity class is generated and cannot carry the attributes itself. Calling it again for the same pair does nothing, so it is safe to call before every save.
ValidateEntities(Dictionary<Type, List<EntityInfo>>, bool)
Validate all the entities in the saveMap.
public List<EntityError> ValidateEntities(Dictionary<Type, List<EntityInfo>> saveMap, bool throwIfInvalid)
Parameters
saveMapDictionary<Type, List<EntityInfo>>Map of type to entities.
throwIfInvalidboolIf true, throws an EntityErrorsException if any entity is invalid
Returns
- List<EntityError>
List containing an EntityError for each failed validation.
Exceptions
- EntityErrorsException
Contains all the EntityErrors. Only thrown if throwIfInvalid is true.
ValidateEntity(EntityInfo, List<EntityError>)
Validates a single entity. Skips validation (returns true) if entity is marked Deleted.
public bool ValidateEntity(EntityInfo entityInfo, List<EntityError> entityErrors)
Parameters
entityInfoEntityInfocontains the entity to validate
entityErrorsList<EntityError>An EntityError is added to this list for each error found in the entity
Returns
- bool
true if entity is valid, false if invalid.