Jan 17, 2015 at 1:25 PM
Edited Jan 17, 2015 at 1:29 PM
Yes, it will get you into trouble. Record objects fetched via
are proxies bound to a session.
You'd have to either map records to cacheable POCOs or use NH stateless session instead of
Using stateless session is simple as this:
private ISessionFactoryHolder _sessionFactoryHolder;
using(var session = _sessionFactoryHolder.GetSessionFactory().OpenStatelessSession())
var myTable = Session.Query<MyRecordClass>().Cacheable();
// Do your stuff on the myTable like you'd do on IRepository<T>.Table
This way whatever comes from the query will be a simple POCO
It's similar to what happens under the hood inside the
implementation, just with a different kind of session.
There are caveats though - you won't be able to fetch records with relations this way. In any other case, ie. when your records contain only simple type properties, this approach works very well.