NHibernate is awesome. I'm using it for the first time in a ASP.NET project. Today I found a nice feature in combination with native SQL queries. One can return unmanaged entities for a native SQL query - with automatic mapping - excellent! See the documentation on using Transformers: (NHibernate native SQL queries)
sess.CreateSQLQuery("SELECT name, birthdate FROM CATS")
.SetResultTransformer(Transformers.AliasToBean(typeof(CatDTO)))
public class CatDTO {
public string Name {
get {}
set {}
}
public DateTime Birthdate {
get {}
set {}
}
}
Just create Properties using the same name as the columns of the query in the POCO and you're done. And the extra nice thing. Exactly the same approach in the original Java version (Hibernate native SQL queries).