Hi
The way i use nhibernte is the following in a asp.net
I´ve got a NHIbernate HttpModule class that instanciate a sesion for request.I´ve a got a DAO for accessing each table. I´ve got a business manager over the dao class. I put an example:
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using com.tinsa.utils.log;
using com.tinsa.utils.nhibernate;
using NHibernate;
namespace com.tinsa.db.dao
{
public class NivelesDAO
{
private static NivelesDAO nivelManager;
private static string className = "NivelesDAO";
public static NivelesDAO getInstance()
{
if (nivelManager == null)
{
nivelManager = new NivelesDAO();
}
return nivelManager;
}
public IList obtenerNiveles()
{
string localizator = "[" + className + ":obtenerNiveles]:";
try
{
ISession sesion = NHibernateHttpModule.CurrentSession;
IList resultList = sesion.CreateQuery("from Nivel").List();
return resultList;
}
catch (Exception e)
{
if (Log.IsErrorEnabled ())
Log.Error(localizator + "Error obteniendo los niveles de la Base de datos." + e.Message, e);
throw e;
}
}
}
}
My doubts are:
* Is it correct the gestinstance or i can delete it?
* I´ve i want to access to table in the same request how can i do that? Maybe i want to look in a table and them insert in another one:
public SLA calcularPrioridad(int urgencia, int usuarios, int degradacion, Incidencia incidencia)
{
string localizator = "[" + className + ":calcularPrioridad]:";
try
{
MatrizDAO matrizManager = MatrizDAO.getInstance();
Prioridad prioridadSalida = matrizManager.obtenerPrioridad(urgencia, usuarios, degradacion, incidencia.Proceso.Requisito);
incidencia.Prioridad = new Prioridad(prioridadSalida);
SLA sla = SLADAO.getInstance().obtenerSLA(prioridadSalida);
return sla;
}
Is that correct? But how can i do to that in the same transaction if the transaction is in the dao layer in not in the business layer?
Best regards
|