【问题标题】:Exception when retrieving record using Nhibernate使用 Nhibernate 检索记录时出现异常
【发布时间】:2010-04-16 17:44:12
【问题描述】:

我是 NHibernate 的新手,现在才刚刚开始。

我有一个非常简单的表,包含 Id(Int 主键和自动递增)、名称(varchar(100))、描述(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'.

请给我建议---谢谢

【问题讨论】:

    标签: asp.net nhibernate fluent-nhibernate


    【解决方案1】:

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

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

    【讨论】:

    • 你能告诉我一件事吗,我怎样才能在我的问题中发布的上述方法中使用 HQL 进行复杂查询?像...select t1.ID, t2.Name from Table1 t1 inner join Table2 on t1.ID = t2.ID where t.ID = 2
    • 我在 Internet 上看到了示例并找到了 HQL,但我无法使用它......... public List getDevelopmentSteps1() { string hql = "From DevelopmentSteps d内连接表2 t2 d.id=t2.Id where d.id=IDValue"; IQuery q = session.CreateQuery(hql); } -----这里我在会话中遇到问题
    • @Muhammad:把它放在一个新问题中。如果你愿意,可以参考这个问题。
    • 您需要定义一个映射到您尝试加入的table2 的类。然后你可以将这个类作为DevelopmentSteps 类中的一个属性,当你尝试获取DevelopmentSteps 实例时,NHibernate 会自动为你生成连接查询。那里有很多教程,谷歌many-to-one nhibernate
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-10-17
    • 1970-01-01
    • 2014-03-26
    • 2013-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多