我有以下代码:
public class Part
{
public virtual int ID { get; set; }
public virtual string Number { get; set; }
public virtual IList<Part> RawItems { get; set; }
...
}
和映射:
<class name="Part" table="PART">
<id name="ID" column="ID" type="Int32">
<generator class="native" />
</id>
<property name="Number" column="NUM" not-null="true" type="String" />
...
<bag name="RawItems">
<key />
<one-to-many class="Part" />
<loader query-ref="GetRawItemsByFinishedPart" />
</bag>
</class>
<sql-query name="GetRawItemsByFinishedPart">
<load-collection alias="p" role="Part.RawItems" />
<![CDATA[
SELECT {p.*}
FROM PART {p}
... and so on valid SQL
问题:当我调用part.RawItems.ToList();我的集合是空的,但是如果我明确地调用sql,它会返回Part实体列表。
我错过了什么吗? 请帮忙。