开发者

NHibernate Cacheing Issue

开发者 https://www.devze.com 2022-12-13 01:17 出处:网络
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 ti

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号