views:

26

answers:

1

Suppose I'm going to do something that needs access to NHibernate's ISession. For example running a Sql query via ISQLQuery or running a LINQ-to-NHibernate via session.Linq<MyType>(). I know there is 2 way to access ISession:

  1. ActiveRecordMediator.GetSessionFactoryHolder().CreateSession()
  2. ActiveRecordMediator.Execute()

What is the pros and cons of each one? additionally is there another alternative ways?

A: 

I can't think of any technical reason to prefer one over the other, however ActiveRecordMediator.Execute is the documented way.

BTW you don't need any of this to do LINQ queries, you can use Castle.ActiveRecord.Linq instead.

Mauricio Scheffer
@Mauricio, It's seems that `ActiveRecord.Execute` handles session automatically but the other way does not. It may be is the cause of prefering `ActiveRecord.Execute` to other way in documentation. BTW is there any sample/documentation about `Castle.ActiveRecord.Linq`?
afsharm
@afsharm: of course, getting the session yourself implies wrapping it in a `using` block. Re LINQ: see http://stackoverflow.com/questions/2967777/how-to-use-linq-with-castle-activerecord
Mauricio Scheffer