NHibernate的陷井
这几天公司准备用NHibernate作为基础框架,上网搜了搜,NHibernate官网提供了几个版本,最基础的是NHibernate,然后NHibernate.Burrow是对前者做了一些封装,NHibernate.Burrow.AppBlock则进一步进行了封装,看了下,确实很方便,于是自己动手写点玩意。
帮助文档都是E文版,所有又好用又不要钱的玩意好像都是外国人搞出来的,好在还不难懂。官网下了个例子,结果中了一个招。请看帮助文档:
Now consider a model of the relationships between Customer, Order and LineItem and Product. There is a one-to-many association between Customer and Order, but how should we represent Order / LineItem / Product? I've chosen to map LineItem as an association class representing the many-to-many association between Order and Product. In NHibernate, this is called a composite element.
![](https://www.cnblogs.com/Images/OutliningIndicators/ContractedBlock.gif)
请看子表名:Order
官网的例子有个Create_SQL的建表语句,如果你按照这个例子做下去,搞一对多的测试,会发现无论如何都会报错,
嘿嘿,想到原因没?老夫我找了好久才搞明白,浪费了大量脑细胞啊。
NHibernate中用代码工具生成的实体类必须要将XML映射文件选成嵌入的资源,才可以正常使用。