I have a Employee class, i am retriving employee data using nhibernate.It gives
complete column.(eq. sql – Select * ). But, if i want to have slected column (like EmployeeName and EmployeeID only),then i need to create a class with these two properties(e.g.Empl class).and using AliasToBeanResultTransformer i.e. Projection i can retrive. I want to know that is there any way in nhibernate (without creating sub classes(Empl class), or without hard coding hql query)so that i can retrive specific column values…
class Employee
{
public int EmployeeId { get; set; }
public string EmployeeName { get; set; }
public int ResidingInCountryId { get; set; }
public virtual Country ResidenceCountry { get; set; }
}
If you only want to project a few columns from a query then you can either
a) use a DTO although you mentioned you don’t like this for some reason
b) if you
REALLYwant a list of anonymous objects then simply omit the result transformer which will result in a list of anonymous objects with the projected values. This would be sufficient for databinding.Also you do not need to use just HQL for projectons, you can use Criteria, QueryOver or NH Linq.