I did a lot of stuff like this, but with my mapping technology (ValueInjecter)
There is a DAL (console app) sample in the download
I am doing this without NHibernate so it's like this:
public static IEnumerable<T> GetAll<T>(string cs) where T : new()
{
using (var conn = new SqlConnection(cs))
{
using (var cmd = conn.CreateCommand())
{
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select * from " + TableConvention.Resolve(typeof(T));
conn.Open();
using (var dr = cmd.ExecuteReader())
{
while (dr.Read())
{
var o = new T();
o.InjectFrom<ReaderInjection>(dr);
yield return o;
}
}
}
}
}
with NHibernate I know there something like
criteriaSelect.SetResultTransformer(NHibernate.Transform.Transformers.AliasToBean(typeof(YourEntity)));
which should do the mapping for you