c# - NHibernate: Could not resolve property: empAlias -


my purpose find employee information in project have projectnumber > 2

this query:

list<employeedao> emplist = new list<employeedao>(); using (isession mysession = sessionfactory().opensession()) {     using (itransaction mytransaction = mysession.begintransaction())     {         employeedao empdaoalias = null;         employee empalias = null;         group groupalias = null;         project projectalias = null;         rank rankalias = null;         employeefunctioninproject efpalias = null;          emplist = mysession.queryover<employee>(() => empalias)             .joinalias(() => empalias.rank, () => rankalias)             .joinalias(() => empalias, () => efpalias.employee)             .inner.joinalias(() => efpalias.project, () => projectalias)                 .where(() => projectalias.projectnumber > 2)             .select(projections.projectionlist()             .add(projections.property(() => empalias.visa).withalias(() => empdaoalias.visa))             .add(projections.property(() => empalias.firstname).withalias(() => empdaoalias.firstname))             .add(projections.property(() => empalias.lastname).withalias(() => empdaoalias.lastname))             .add(projections.property(() => empalias.firstname).withalias(() => empdaoalias.project))             .add(projections.property(() => rankalias.name).withalias(() => empdaoalias.rank)))             .transformusing(transformers.aliastobean<employeedao>())             .list<employeedao>().tolist();     } } return emplist; 

i got error

could not resolve property: empalias of: myweb10.models.employee

i doub problem occurs in line .joinalias(() => empalias, () => efpalias.employee)

my employee class

public class employee {     private int _id;     private rank _rank;     private string _visa;     private string _firstname;     private string _lastname;     private datetime? _birthday;     private string _university;     private datetime _rowversion;     public employee() {         employeefunctioninproject = new list<employeefunctioninproject>();         group = new list<group>();     }     public virtual int id {         {             return this._id;         }         set {             this._id = value;         }     }     public virtual rank rank {         {             return this._rank;         }         set {             this._rank = value;         }     }     public virtual string visa {         {             return this._visa;         }         set {             this._visa = value;         }     }     public virtual string firstname {         {             return this._firstname;         }         set {             this._firstname = value;         }     }     public virtual string lastname {         {             return this._lastname;         }         set {             this._lastname = value;         }     }     public virtual datetime? birthday {         {             return this._birthday;         }         set {             this._birthday = value;         }     }     public virtual string university {         {             return this._university;         }         set {             this._university = value;         }     }     public virtual datetime rowversion {         {             return this._rowversion;         }         set {             this._rowversion = value;         }     }     public virtual ilist<employeefunctioninproject> employeefunctioninproject { get; set; }     public virtual ilist<group> group { get; set; } } 

my employeefunctioninproject class

public class employeefunctioninproject {     private int _id;     private function _function;     private project _project;     private employee _employee;     private datetime _rowversion;     public virtual int id {         {             return this._id;         }         set {             this._id = value;         }     }     public virtual function function {         {             return this._function;         }         set {             this._function = value;         }     }     public virtual project project {         {             return this._project;         }         set {             this._project = value;         }     }     public virtual employee employee {         {             return this._employee;         }         set {             this._employee = value;         }     }     public virtual datetime rowversion {         {             return this._rowversion;         }         set {             this._rowversion = value;         }     } } 

my employee mapping

<hibernate-mapping assembly="myweb10" namespace="myweb10.models" xmlns="urn:nhibernate-mapping-2.2">   <class name="employee" table="employee" lazy="true" >     <id name="id" column="id">       <generator class="identity" />     </id>     <many-to-one name="rank">       <column name="rank" sql-type="int" not-null="true" />     </many-to-one>     <property name="visa">       <column name="visa" sql-type="varchar" not-null="true" unique="true" />     </property>     <property name="firstname">       <column name="first_name" sql-type="varchar" not-null="true" />     </property>     <property name="lastname">       <column name="last_name" sql-type="varchar" not-null="true" />     </property>     <property name="birthday">       <column name="birthday" sql-type="date" not-null="false" />     </property>     <property name="university">       <column name="university" sql-type="varchar" not-null="true" />     </property>     <property name="rowversion">       <column name="rowversion" sql-type="timestamp" not-null="true" />     </property>     <bag name="employeefunctioninproject" inverse="true">       <key column="employee" />       <one-to-many class="employeefunctioninproject" />     </bag>     <bag name="group" inverse="true">       <key column="leader" />       <one-to-many class="group" />     </bag>   </class> </hibernate-mapping> 

my employeefunctioninproject mapping

<hibernate-mapping assembly="myweb10" namespace="myweb10.models" xmlns="urn:nhibernate-mapping-2.2">   <class name="employeefunctioninproject" table="employee_function_in_project" lazy="true" >     <id name="id" column="id">       <generator class="identity" />     </id>     <many-to-one name="function">       <column name="function" sql-type="int" not-null="false" />     </many-to-one>     <many-to-one name="project">       <column name="project" sql-type="int" not-null="false" />     </many-to-one>     <many-to-one name="employee">       <column name="employee" sql-type="int" not-null="false" />     </many-to-one>     <property name="rowversion">       <column name="rowversion" sql-type="timestamp" not-null="true" />     </property>   </class> </hibernate-mapping> 

in these case, when want filter root/parent entity of collection/child memebers, should use subqueries (inner select)

employeefunctioninproject efpalias = null; employee empalias = null; project projectalias = null;  // subquery, selecting 2 pair table , project table var subquery = queryover.of<employeefunctioninproject>(() => efpalias)     .joinalias(() => efpalias.entity, () => projectalias)     // projectnumber on 2     .where(() => projectalias.projectnumber > 2)     // id of employee     .select(x => efpalias.employee.id);  // root query, on employee var list = session.queryover<employee>(() => empalias)     .withsubquery        .whereproperty(() => empalias.id)        .in(subquery)     // rest of query     ...// take(), skipe(), select(), list() 

see more here:


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -