Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4624766
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T03:10:33+00:00 2026-05-22T03:10:33+00:00

I want to map SQL query to Business object using Nhibernate . There are

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T03:10:33+00:00Added an answer on May 22, 2026 at 3:10 am

    I think you would benefit from using NHibernate’s ad-hoc mapping features:

    Named query:

    <?xml version="1.0" encoding="utf-8" ?>
    <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
        <sql-query name="findEmployeesInfo">
          select emp.Eid as Id, emp.FirstName FirstName, emp.LastName as LastName from Employee emp
        </sql-query>
    </hibernate-mapping>
    

    Employee class:

    public class Employee
    {
        public int Id { get; set; }
        public string FirstName { get; set; }
        public string LastName { get; set; }
        // etc...
    }
    

    Ad-hoc query:

    IList<Employee> employees = session
                                  .GetNamedQuery("findEmployeesInfo")
                                  .SetResultTransformer(Transformers.AliasToBean(typeof(Employee)))
                                  .List<Employee>();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a way in NHibernate to map the result of a count query
I have this object graph, I want to map: abstract Account (username, password, ...)
I want to have a map that has a homogeneous key type but heterogeneous
I want something like an std::map , but I only want to see if
I get my information from my SQL query (Name, Description, Latitude, Longitude) but I'm
I want to map a class to a table and a subclass to another
i want to Map a map in JPA, but I get a Exception: My
I have a database field called abCode , that I want to map to
I want to fill a map with class name and method, a unique identifier
I want to texture a sphere with a cube map. So far my research

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.