简体   繁体   English

通过IUserType映射集合

[英]mapping a collection via IUserType

I need to load a class (Adjustment) with some logic, so I implemented the IUserType in Nhibernate. 我需要使用一些逻辑加载类(调整),因此我在Nhibernate中实现了IUserType。 When it's a single reference, it works fine: 当是单个引用时,它可以正常工作:

    Map(p => p.DefaultAdjustment)
        .CustomType(typeof(AdjustmentCustomMap));

Its SqlType is string. 它的SqlType是字符串。
However, I have a collection from Adjustment as well, I dont know how can I map it ! 但是,我也有来自Adjustment的集合,我不知道该如何映射它!

        HasMany(p => p.Adjustments)
            .Cascade.AllDeleteOrphan()
            .Inverse())
            ;

how can I get my implementation of IUserType to load the collection? 如何获得IUserType的实现以加载集合?
I'm using NH 3.3 我正在使用NH 3.3
Thanks in advance. 提前致谢。

Try using .Element() with your HasMany mapping. 尝试将.Element()HasMany映射一起使用。 Since you are not mapping a collection of entities, but a collection of simple objects, you need to use the same mapping as you would have if mapping a collection of string , int , Guid ... 由于您不是在映射实体集合,而是在映射简单对象的集合,因此您需要使用与映射stringintGuid ...的集合相同的映射。

HasMany(p => p.Adjustments)
    .Element("Adjustment", e => e.Type<AdjustmentCustomMap>())
    .Cascade.AllDeleteOrphan()
    .Inverse())
    ;

The first parameter of Element method is a column name. Element方法的第一个参数是列名。

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

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