使用Nhibernate检索记录时出现异常

时间:2010-04-16 09:42:09

标签: asp.net nhibernate fluent-nhibernate

我是NHibernate的新手,刚刚开始。

我有一个非常简单的表包含Id(Int主键和自动递增),Name(varchar(100)),Description(varchar(100))

这是我的XML

<class name="DevelopmentStep" table="DevelopmentSteps" lazy="true">
<id name="Id" type="Int32" column="Id">
</id>
<property name="Name" column="Name" type="String" length="100" not-null="false"/>
<property name="Description" column="Description" type="String" length="100" not-null="false"/>

这是我想要获得所有记录的方式

 public List<DevelopmentStep> getDevelopmentSteps()
   {
       List<DevelopmentStep> developmentStep;
       developmentStep = Repository.FindAll<DevelopmentStep>(new OrderBy("Name", Order.Asc));
       return developmentStep;
   } 

但我得到例外

The element 'id' in namespace 'urn:nhibernate-mapping-2.2' has incomplete content. List
 of possible elements expected: 'urn:nhibernate-mapping-2.2:meta urn:nhibernate-mapping-
2.2:column urn:nhibernate-mapping-2.2:generator'.

请告诉我---谢谢

1 个答案:

答案 0 :(得分:4)

您需要在映射中指定id的生成器类型:

<id name="Id" type="Int32" column="Id">
    <generator class="native" />
</id>