简体   繁体   English

NHibernate自定义列表组件映射

[英]NHibernate Custom List Component Mapping

I'm working with a codebase that has the equivalent to the following: 我正在使用与以下代码等效的代码库:

public class CustomList<T> : List<T>

And then in a subsequent Class 然后在下一堂课

public interface ISomeObject {
    string Name { get; set; }
    CustomList<ISomeOtherObject> SomeOtherObjects { get; set; }
}

Now in the Mapping file for a normal List the xml would be (I've checked this works): 现在,在映射文件中的普通列表中,xml将是(我已经检查了这是可行的):

<list name="SomeOtherObjects " table="SomeOtherObject">
    <key column="Id"/>
    <index column="Reference"/>
    <composite-element class="SomeOtherObject" />
</list>

I need to find out what the equivalent xml is for the CustomList. 我需要找出与CustomList等效的xml。 I've googled and searched here until I am blue in the face finding bits and pieces about components and how to map custom collections but so far I've not been able to find enough to get me over this hurdle. 我一直在这里搜索和搜索,直到脸色发青,找到有关组件以及如何映射自定义集合的点点滴滴,但到目前为止,我还找不到足够的东西来解决这个问题。 I am trialing and erroring like mad with all the different properties so if anyone has a snippet example of how to map a custom list I'd be very greatful. 我正在疯狂地尝试和错误对待所有不同的属性,因此,如果有人有如何映射自定义列表的摘要示例,我将非常感激。

Cheers. 干杯。

Your mapping is on the right path, but incomplete. 您的映射在正确的路径上,但是不完整。 It should look something like this. 它看起来应该像这样。

<list name="SomeOtherObjects " table="SomeOtherObject">
    <key column="Id"/>
    <index column="Reference"/>
    <composite-element class="SomeOtherObject" >
        <property name="SomeOtherObjectProperty" />
        <!-- More properties that are defined in SomeOtherObject here. -->
    </composite-element>
</list>

This post may help you understand more about collection mapping. 这篇文章可以帮助您了解有关集合映射的更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM