代码之家  ›  专栏  ›  技术社区  ›  NetSide

Nhibernate Linq:会话结束后如何使用Iqueryable列表?

  •  1
  • NetSide  · 技术社区  · 15 年前

    var bundles = session.Linq<Bundle>();
    session.Close();
    var bs = bundles.ToList();
    

    我得到一个错误,有不同的语法吗?

    2 回复  |  直到 15 年前
        1
  •  2
  •   Sly    15 年前

    你不能。会话用于保持与数据库的连接。关闭会话后,无法访问数据库

        2
  •  1
  •   tinonetic    8 年前

    public void DoSomethingWithData()
    {
        IList<Bundles> qbundles;
        using (var uof = new UnitOfWork())
        {
             IQueriable<Bundle> bundles = uof.Repository<Bundle>().Query();
             // just a litte example... replace with whatever
             qbundles = bundles.Where(b => b.Qty == 5).ToList()
        }
        ....
    }
    

    以下是一些可以让您开始使用此模式的链接:

    http://web.archive.org/web/20090803155753/http://blogs.hibernatingrhinos.com/nhibernate/archive/2008/04/10/nhibernate-and-the-unit-of-work-pattern.aspx

    http://nhforge.org/wikis/patternsandpractices/nhibernate-and-the-unit-of-work-pattern.aspx