Nhibernate-Linq: How can I use Iqueryable list after session close?
Is it possible to get list after Session.Close as below?
var bundles = session.Linq<Bundle>();
session.Close();
var bs = bundles.ToLi开发者_JAVA技巧st();
I get error, is there a different syntax for that?
You can't. Session is used for holding a connection to the data base. After you close the session, you cant get access to DB
It looks like you're going about this the wrong way. You need to use the UnitOfWork pattern. INSIDE you're unit of work is where you do things with your IQueriable. You can't just pass an IQueriable around because of it's dependence on an ISession. Perhaps your syntax will look like this:
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()
}
....
}
Here are some links that might get you started with this pattern:
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
精彩评论