By default, the object is added to the cache. When you create an object, you can explicitly set its entityState to Detached or any other state if you want. ( entityManager.createEntity('entityType', null, breeze.EntityState.Detached) )
As for validation, you can manually verify entities in any state at any time. If you want to validate when a property changes, just subscribe to the entityAspect.propertyChanged event. The propertyChanged event will give you access to the entity itself, the name of the changed property, the old value and the new value. Then you just need to check the validation of properties using entity.entityAspect.validateProperty(propertyname) and process the results.
Sign up for property changes and manually confirm
(The code below is combined with breeze examples)
// assume order is an order entity attached to an EntityManager. order.entityAspect.propertyChanged.subscribe( function (propertyChangedArgs) { // this code will be executed anytime a property value changes on the 'order' entity. var entity = propertyChangedArgs.entity; // Note: entity === order var propertyNameChanged = propertyChangedArgs.propertyName; var oldValue = propertyChangedArgs.oldValue; var newValue = propertyChangedArgs.newValue; if (!entity.entityAspect.validateProperty(propertyNameChanged)){ //Property is not valid. Inform the user if needed. } });
For more help and examples, see these links:
Subscribe to propertyChanged event
Manual property check
Create a new object
source share