Since we track dirty status on our entities ourselves, it's easy for us to know if a detached entity has been modified. Still, I tried doing something like
Code:
if (entityToAttach.IsModified)
session.Update(entityToAttach);
else
session.Refresh(entityToAttach, LockMode.None);
However, often when it tries to do a Refresh(), I get exceptions like "cannot modify a loading collection". I don't know if the same errors occur with plain-old Lock() instead of Refresh(), but it seems that if you're going to reattach a detached entity, you should make sure it's not stale.
For the time being, we're always doing Update(), and if an exception gets thrown, do a Get() and then manually, painstakingly merge in any dirty properties on the entity originally requested for reattachment, return the one from the session and expect the caller to deal with the fact that the instance "attached" is not the one passed ...