Mapping not returning excepting results - Nhibernate

Viewed 28

I'm trying to get list of students with their courses but I don't want to get all courses of each students.

class Instructor {

public virtual int Id {get;set;}
public virtual string Name {get;set;}
public List<Courses> Course {get;set;}

Class Course {
 public virtual int Id {get;set;}
 public virtual string Name {get;set;}
 public virtual string Code {get;set;}
 public virtual string levelCode {get;set;}
 public Instructor instructor {get;set;}
}

Course Xml :

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
    namespace="Registration" assembly="Registration">

    <class name="Course" table="Course">
         // some implementation
        <many-to-one name="Instructor " not-found="ignore">
      <column name="InstructorId" sql-type="int" not-null="false" />
     </many-to-one>
          
    </class>

</hibernate-mapping>

I tried the following query but it didn't return the excepted results which is one single object instead of list,however I'm getting instructors list with all their courses

Instructor instAlias = null;
        Course courseAlias= null;
        var query = Session.QueryOver<Instructor >(() => instAlias )
            .JoinAlias(() => instAlias.Course, () => courseAlias)
            .Where(() => courseAlias.levelCode  == 5)
            .List(); 
0 Answers
Related