Table of Contents

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

persistenceManager PersistenceManager

Used 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

entityType Type

The entity type being validated.

metadataType Type

The 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

saveMap Dictionary<Type, List<EntityInfo>>

Map of type to entities.

throwIfInvalid bool

If 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

entityInfo EntityInfo

contains the entity to validate

entityErrors List<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.