An Petshop4.0 architecture that uses an ORM framework in the solid layer NHibernate
Package NH access to business objects is as follows:
/// <summary>
/// 查询记录
/// </summary>
/// <param name="hql">HQL语句</param>
/// <param name="args">HQL语句中的参数值</param>
/// <returns>IList<T></returns>
public IList<T> Select<T>(string hql, Dictionary<string, object> args)
{
try
{
session = NHibernateDatabaseFactory.CreateSession();
IQuery query = session.CreateQuery(hql);
if (args != null)
{
this.PrepareQuery(query, args);
}
return query.List<T>();
}
catch (Exception err)
{
throw err;
}
}
There are two ways to load a business object.
Mode one:
Entity layers: Defining generic access Methods in the Basedal class
public statci IList<T> GetData<T>(string hql)
{
return new NHUtility.NHibernateHelper().Select<T>(hql);
}
Business Layer Access:
such as employee business layer:
public List<EmployeeInfo> GetData()
{
List<EmployeeInfo> emps = (List<EmployeeInfo>) BaseDAL.GetData<EmployeeInfo>("From Employee E");
}
In this way, each business object has to implement the GetData method at the business layer.