I want to map SQL query to Business object using Nhibernate. There are lot fields in Employee table, but I am getting three only and want map only those one.
here is my sql query
<sql-query name="findEmployeesInfo">
<return alias="emp" class="Calibr.BusinessDocuments.BOs.Employee, BusinessDocuments"/>
<![CDATA[
select (emp.Eid) as {emp.Id},(emp.FirstName) as {emp.FirstName},(emp.LastName) as {emp.LastName} from Employee emp
]]>
</sql-query>
here is I have make constructor to map those columns
public Employee(int Id, string FirstName, string LastName)
{
this.Id = Id;
this.FirstName = FirstName;
this.LastName = LastName;
}
DB Employee table Column Names: Eid, FirstName,LastName,…………
I am getting this exception
could not execute query
[ select (emp.Eid) as Eid1_0_,(emp.FirstName) as FirstName1_0_,(emp.LastName) as LastName1_0_ from Employee emp
Edit: if I select all columns, it will work perfect — Select * from Employee emp
Thanks for your help.
I think you would benefit from using NHibernate’s ad-hoc mapping features:
Named query:
Employee class:
Ad-hoc query: