Hi
I've been using NHibernate v. 2.0.1 for a year and I find it to be a
great ORM.
Recently I found myself in the situation to manage my own db
connections and to use as less db connections as possible (ideally one
db connection per process).
I've made some tests where I open parallel ISessions providing the
same instance of my own IDbConnection to each session, load data,
change it and save it back to db and it works just fine.
Here is an example of my test:
System.Configuration.Configuration config =
System.Configuration.ConfigurationManager.OpenExeConfiguration
(System.Configuration.ConfigurationUserLevel.None);
System.Configuration.ConnectionStringSettings sett =
System.Configuration.ConfigurationManager.ConnectionStrings[0];
conn = new SqlConnection(sett.ConnectionString);
conn.Open();
ISession s1 = _sessFactory.OpenSession(conn);
ISession s2 = _sessFactory.OpenSession(conn);
IList<Building> buildings = s2.CreateQuery("from
Building").List<Building>();
IList<Item> items = s1.CreateQuery("from Item").List<Item>
();
items[1].Name = "item21";
using (ITransaction transaction = s1.BeginTransaction())
{
s1.Save(items[1]);
transaction.Commit();
}
buildings[0].Height = 10;
using (ITransaction transaction = s2.BeginTransaction())
{
s2.Save(buildings[0]);
transaction.Commit();
}
Nevertheless NHibernate reference advices against this practice but
unfortunatelly without giving a reason why.
Can someone pls tell me what can possibly go wrong in a scenario like
this?
Thanks a lot.
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.