简体   繁体   English

NHibernate FlushMode.Commit自动保存脏对象

[英]NHibernate FlushMode.Commit auto saves dirty objects

I seem to miss something here : 我似乎在这里错过了一些东西:

I have an application that uses a session per application method and using lazy loading. 我有一个应用程序,它使用每个应用程序方法的会话并使用延迟加载。

I've set the session FlushMode.Commit and it seems that NHibernate still auto saves my dirty objects to the DB (SQLCe) although I never begin a transaction and commit it. 我已经设置了会话FlushMode.Commit,尽管我从未开始过事务并提交它,但NHibernate似乎仍会自动将我的脏对象保存到数据库(SQLCe)中。

can anyone tell me what am I doing wrong ? 谁能告诉我我在做什么错?

some of my code : 我的一些代码:

    public Repository(ISessionProvider sessionProvider)
    {
        _sessionProvider = sessionProvider;
        _session = _sessionProvider.OpenSession();
        _session.FlushMode = FlushMode.Commit;
    }

    public IList<T> GetAll<T>() where T : class
    {
        var criteria = _session.CreateCriteria<T>();
        var list = criteria.List<T>();
        return list;
    }

It seems that I had another thread that was flushing the same session while I was creating a dirty object in my UI, I guess it was just a bug in my application. 似乎我在UI中创建脏对象时,另一个线程正在刷新同一会话,我想那只是我的应用程序中的错误。

works Great now, still using a session per application since I need the Lazy feature. 现在工作正常,因为我需要惰性功能,所以仍在每个应用程序上使用会话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM