Search code examples
nhibernatehqlcastle-activerecord

How do I return a limited set of columns in a Castle ActiveRecord query?


and have it map to a strongly typed object?

Suppose I have a entity Blog with Id,Name,Posted,IsUglyFace,YerMom

but I just only want/need Name and Posted columns. I tried to do something like:

IList blogs = repository.SimpleQuery("select Name, Posted from Blog");

This dumps out a ton more SQL and gives back an error, could not map to given object.


Solution

  • See http://ayende.com/Blog/archive/2007/08/26/Partial-Object-Queries-With-NHibernate.aspx

    Bonus: http://ayende.com/Blog/archive/2007/08/26/Lazy-Property-Loading-In-NHibernate.aspx