Reputation: 3267
I found this piece of code:
public virtual void Update(T entity) {
Logger.Debug("Update {0}", entity);
Session.Evict(entity);
Session.Merge(entity);
}
Can you explain what are pros and cons of calling this over calling update on session? Why is this working, what are mechanics behind this code? Is it not too hacky?
Upvotes: 0
Views: 1460
Reputation: 38618
Session.Evict
will evicts a single object from the session, for sample, if you already have an obj
on the session and you try to call session.Update(entity)
you will get an exception saying that this obj
is on the session and you cannot update.
Session.Merge
will merge an single object with the existent object on the session (cache) and update.
take a look: https://stackoverflow.com/a/9161057/316799
Upvotes: 1