最近刚学习NHibernate,但是做一个多表查询就出了问题
_session.CreateQuery("select distinct c from Usr c ,"
+ " c.OrderTbls o where o.OrderDesc like :orderDate").SetString("orderDate", "%" + strOrderDesc + "%")
.List<Usr>();
上面是我写的HQL,但总是报c.OrderTbls is not mapped [select distinct c from myProject.Model.Usr c , c.OrderTbls o where o.OrderDesc like :orderDate]
我的XML是
<id name="UserId" column="UserId" type="System.Int64" unsaved-value="0">
<generator class="native" />
</id>
<property name="UserName" column="UserName" type="System.String" />
<property name="Password" column="PassWord" type="System.String" length="50" />
<property name="State" column="State" type="System.String" length="50" />
<property name="CreateTime" column="CreateTime" type="System.DateTime" />
<!--一对多关系:Customer有一个或多个Orders-->
<set name="OrderTbls" table="OrderTbl" generic="true" inverse="true">
<key column="UserId" foreign-key="FK_OrderTbl_Usr"/>
<one-to-many class="myProject.Model myProject.Model.OrderTbl,"/>
</set>
请高手帮忙指点一下 感激不尽!!!!!!
left join fetch c.OrderTbls o 试试
集合需要join查询。。。