문제

I need to load a class (Adjustment) with some logic, so I implemented the IUserType in Nhibernate. When it's a single reference, it works fine:

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

Its SqlType is string.
However, I have a collection from Adjustment as well, I dont know how can I map it !

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

how can I get my implementation of IUserType to load the collection?
I'm using NH 3.3
Thanks in advance.

도움이 되었습니까?

해결책

Try using .Element() with your HasMany mapping. 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...

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

The first parameter of Element method is a column name.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top