Session: How to Ignore Entity Changes
In order to mark an entity as one that should be ignored for change tracking purposes, use the ignoreChangesFor
method from the advanced
session operations.
Unlike the evict
method, performing another Load
of that entity won't create a call to the server.
The entity will still take part in the session, but will be ignored for saveChanges
.
Syntax
void ignoreChangesFor(Object entity);
Parameters | ||
---|---|---|
entity | Object | Instance of entity for which changes will be ignored. |
Example
Product product = session.load(Product.class, "products/1-A");
session.advanced().ignoreChangesFor(product);
product.unitsInStock++; //this will be ignored for SaveChanges
session.saveChanges();