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

  • Home
  • SEARCH
  • 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 3459190
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:04:34+00:00 2026-05-18T10:04:34+00:00

How to convert this NHibernate HQL(works) … static IList<Phone> PhoneList() { ISession session =

  • 0

How to convert this NHibernate HQL(works) …

static IList<Phone> PhoneList()
{
    ISession session = OpenSession();

    IQuery query = session.CreateQuery("from Phone p where p.Kontact.ContactName = :_contact_name");
    query.SetParameter("_contact_name", "lennon");

    IList<Phone> contacts = query.List<Phone>();

    return contacts;        
}

…to Linq-to-NHibernate(not working):

static IList<Phone> PhoneListUsingLinq()
{
    string contactName = "lennon";

    ISession session = OpenSession();

    var contacts = from Phone p in session.Query<Phone>()
        where p.Kontact.ContactName == contactName
        select p;

    return contacts.ToList();

}

The objects:

public class Contact
{
    public virtual int ContactId { get; set; }
    public virtual string ContactName { get; set; }

    public virtual IList<Phone> Phones { get; set; }


}

public class Phone
{  
    public virtual Contact Kontact { get; set; }
    public virtual int PhoneId { set; get; }
    public virtual string PhoneNumber { get; set; }
}

Here’s the .hbm.xml mapping file of that two objects:

<?xml version="1.0" encoding="utf-8" ?>

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" auto-import="true" assembly="TestTwoTable" namespace="TestTwoTable">

  <class name="Contact" table="contact">
    <id name="ContactId" column="contact_id">
      <generator class="sequence">
        <param name="sequence">contact_contact_id_seq</param>
      </generator>
    </id>

    <property name="ContactName" column="contact_name"/>

    <bag name="Phones" inverse="true">
     <key column="contact_id"/>
     <one-to-many class="Phone"/>
    </bag>

  </class>

  <class name="Phone" table="phone">
    <id name="PhoneId" column="phone_id">
      <generator class="sequence">
        <param name="sequence">phone_phone_id_seq</param>
      </generator>
    </id>

    <property name="PhoneNumber" column="phone_number"/>

    <many-to-one name="Kontact" column="contact_id" class="Contact" not-null="true"/>

  </class>

</hibernate-mapping>

What’s wrong with this?

var contacts = from Phone p in session.Query<Phone>()
               where p.Kontact.ContactName == contactName
               select p;

Note: I’m using NHibernate 3

  • 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-18T10:04:34+00:00Added an answer on May 18, 2026 at 10:04 am

    Change “from Phone p” to “from p”

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to group table values by date, and this HQL query works fine:
Need to convert this sql query to nhibernate criterion language... How can I do
I am try to convert the following NHibernate query using dyanmic instantiation into an
I want to convert following native sql query to hql query. I gone through
convert this: $300 to this : 300 can't do it with intval() or (int)
I am trying to convert this test code to C# and having a problem
How can i convert this to a decimal in SQL? Below is the equation
Please help me convert this line to C#. objManagementBaseObject.SetPropertyValue(hDefKey, CType(&H & Hex(RegistryHive.LocalMachine), Long)) Related
I want to convert this linear loop into a concurrent one: for(Item item :
Can anyone help convert this this actionscript to Objective-c? if(mcMain.y >= stage.stageHeight - mcMain.height)

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.