我的NHibernate书有错吗?
我开始学习 NHibernate (3.0) 并拿起了 Packt Publishing 的 的副本NHibernate 3.0 食谱。
我正在浏览一个关于一对多映射的部分,但使用的是我自己的数据库。它建议我应该做这样的事情来建模客户及其域之间的一对多关系:
public class Customer
{
public virtual int Id { get; protected set; }
public virtual string CustomerName { get; set; }
// Customer has many domains
public virtual IList<Domain> Domains { get; set; }
}
public class Domain
{
public virtual int Id { get; protected set; }
public virtual int CustomerID { get; set; }
public virtual string DomainName { get; set; }
}
客户映射:
<class name="Customer" table="tblCustomer">
<id name="Id">
<column name="CustomerID" sql-type="int" not-null="true"/>
<generator class="identity"/>
</id>
<property name="CustomerName" column="Customer"/>
<list name="Domains">
<key column="CustomerID"/>
<one-to-many class="Domain" />
</list>
</class>
当我运行此命令时,我收到以下错误:
XML验证错误:命名空间“urn”中的元素“list” :nhibernate-mapping-2.2' 在命名空间 'urn:nhibernate-mapping-2.2' 中具有无效的子元素 'one-to-many'。预期可能元素的列表:命名空间“urn:nhibernate-mapping-2.2”中的“index, list-index”。
本书的示例有点复杂,因为它们使用每个子类的表映射:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
assembly="Eg.Core"
namespace="Eg.Core">
<subclass name="Movie" extends="Product">
<property name="Director" />
<list name="Actors" cascade="all-delete-orphan">
<key column="MovieId" />
<index column="ActorIndex" />
<one-to-many class="ActorRole"/> <-- Is this wrong?
</list>
</subclass>
</hibernate-mapping>
我猜这本书是错的?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不,您的映射缺少
index
元素。 NHibernate 中的列表是有序集,如果您想要无序集,请使用包映射。No, your mapping is missing the
index
element. A list in NHibernate is an ordered set, if you want an unordered set use bag mapping.