Hi All
How can I refresh the persistent objects in a session, so that the object is updated with the data in the database ?
The problem is, I have 2 applications.
The 1st reads the entities with:
Code:
var Users session.Query<User>();
Then the 2nd reads the entities with the same statement and adds more datasets:
Code:
var Users2 session.Query<User>();
User user = new User("Hans", "Muster");
Users2.Add(user);
session.SaveOrUpdate(Users2);
But then, when the first application wants to add more datasets, I get the following error:
"a different object with same identifier value was already associated with the session"I tried everything like:
Code:
session.Evict(Users)
Users = Users session.Query<User>();
Users.Add(......)
session.SaveOrUpdate(Users2);
or:
Code:
Users = Users session.Query<User>();
session.Merge(Users);
Users.Add(......)
session.SaveOrUpdate(Users2);
or:
Code:
session.Flush();
Users = Users session.Query<User>();
Users.Add(......)
session.SaveOrUpdate(Users2);
without success.
However, I could close the session and reopen it, but I don't want to do this as I want to use lazy loading which does not allow to close a session.
So please, how can a refresh or better reread data from the database into a persistent object, so that this error exception can be avoided.
Thank you for your hints
Tom