A Generic method that takes GenericList as an argument and fill it with the data of type you pass as
the non-typed collection contains anything that cannot be casted to type of T.
The sample method uses CSLA framework with Database layer as NHibernate.
You can get CSLA from http://www.lhotka.net/ where as its NHibernate addon is available at http://www.codeplex.com/ under CSLA Contributions.
Here's the code you are looking for
public static void FillList
{
list = null;
// Get an NHibernate session factory where DatabaseKey = connectionstring
ISessionFactory sessionFactory = Csla.NHibernate.Cfg.GetSessionFactory(DatabaseKey);
// Open an NHibernate session from the factory
using (ISession session = sessionFactory.OpenSession())
{
// Begin a transaction on the session
using (ITransaction transaction = session.BeginTransaction())
{
try
{
System.Collections.IList listOfObjects = session.CreateCriteria(typeof(T)).List();
T[] temp = new T[listOfObjects.Count];
listOfObjects.CopyTo(temp, 0);
list = new List
catch (HibernateException)
{
if (null != transaction)
{
transaction.Rollback();
}
}
}
}
}
Generic List for NHibernate
Posted by Zafar Ullah - zafarjcp@gmail.com | 8:24 AM | .net, ASP.NET, C#, Hibernate, NHibernate, ORM, SQL Server 2005 | 0 comments »
Subscribe to:
Post Comments (Atom)
0 comments
Post a Comment