如何使用 FluentNHibernate 映射 NHibernate 自定义集合?
我试图绘制两天的集合图但没有成功。我还阅读了所有可能的文章和论坛,但仍然在那里。好的,问题来了:
1)集合类包含一个私有字段“_internalCollection”,它与 NHib 映射。
2) 持有实体应通过只读属性公开集合。
3)我想避免实现NHibernate接口IUserCollectionType!!!
我用 xml 映射做到了这一点,效果很好。 WarehouseEntity 是一个集合 Item。 Warehouses 是 OrgEntity 类中的只读属性。
<component name="Warehouses" class="Core.Domain.Collections.EntitySet`1[Core.Domain.OrgStructure.IWarehouseEntity,Core],Core">
<set name="_internalCollection" table="`WAREHOUSE`" cascade="save-update" access="field" generic="true" lazy="true" >
<key column="`WarehouseOrgId`" foreign-key="FK_OrgWarehouse" />
<!--This is used to set the type of the collection items-->
<one-to-many class="Domain.Model.OrgStructure.WarehouseEntity,Domain"/>
</set>
</component>
知道如何使用流畅的 NHibernate 来做到这一点吗?
编辑:Core.Domain.Collections.EntitySet`1 是基集合类。它提供了处理集合的基本功能,并且可以适合任何 IEntity 接口的类。
I am trying to map the collection for two days without success. I also read all possible articles and forums but still down there. Ok, here is the problem:
1) The collection class contains a private field "_internalCollection" which is mapped with NHib.
2) The holding entity should expose the collection trough readonly property.
3) I want to avoid implementing NHibernate interface IUserCollectionType!!!
I did this with xml mapping and it work great. The WarehouseEntity is a collection Item. Warehouses is a readonly property in OrgEntity class.
<component name="Warehouses" class="Core.Domain.Collections.EntitySet`1[Core.Domain.OrgStructure.IWarehouseEntity,Core],Core">
<set name="_internalCollection" table="`WAREHOUSE`" cascade="save-update" access="field" generic="true" lazy="true" >
<key column="`WarehouseOrgId`" foreign-key="FK_OrgWarehouse" />
<!--This is used to set the type of the collection items-->
<one-to-many class="Domain.Model.OrgStructure.WarehouseEntity,Domain"/>
</set>
</component>
Any idea how can I do it with fluent NHibernate?
EDIT: Core.Domain.Collections.EntitySet`1 is base collection class. It provides basic functionality for working with collections and can fit any class which is IEntity interface.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
编辑:我错过了问题的关键部分,所以这是另一个尝试:
我确信不是这样,但希望它能让您走上正确的道路。还可以使用 ComponentMap 看看。
我的建议是完全避免自定义集合。我用
IEnumerable
上的扩展方法替换了我们的所有方法。Try:
Edit: I missed a key part of the question so here's another try:
I'm sure that's not it but hopefully it puts you on the right path. Also have a look using ComponentMap.
My advice is to avoid custom collections entirely. I replaced all of ours with extension methods on
IEnumerable<T>
.