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

I have the following sql query and I want to map it to a
Is there a way in NHibernate to map the result of a count query
I want to map a INI file as a python object. So if the
I want to map DbConnection to an un-opened SqlConnection using Ninject . This is
I want to map a Tag entity using declarative method with SQLAlchemy. A tag
My User table I want to map to aspnet_Users: <class name=User table=`User`> <id name=ID
I have one very general object that I want to map to a destination
I have this object graph, I want to map: abstract Account (username, password, ...)
I haev an object with a DateTime property. I want to map the time
I get my information from my SQL query (Name, Description, Latitude, Longitude) but I'm

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.