I've got a Service I'm attempting to move over to NHibernate.
Theres a Get method on the service that is called via a cancel button on the view. The first time the Get method is called (the first time I cancel a change) the cancel actually happens and the value returns.
The second time I cancel, it just ignores the cancel and keeps the new value?!
private ISession _session;
private ISession GetSession()
{
return _session ?? (_session = _sessionFactory.OpenSession());
}
public MappingCollection Get(string id)
{
var session = GetSession();
var mappingCollection = session.Get<MappingCollection>(id);
return mappingCollection;
}
However if I change the Get(string id) to include a refresh ...
p开发者_如何学Pythonublic MappingCollection Get(string id)
{
var session = GetSession();
var mappingCollection = session.Get<MappingCollection>(id);
session.Refresh(mappingCollection);
return mappingCollection;
}
Everything works - but looking with NHibernate Profiler it calls the select twice on the first operation ... I know I could add a bool to see if its been run, but i'm hoping theres a better way!
Can anyone help please? Thanks
Do you kill your web proxy on each cancel attempt? This sounds like a one-session-per-request issue.
And it should make sense that the second version gets run twice. First, you get the item. Then you refresh the item. That will make a call to the data store to check for changes.
精彩评论