2009-09-03 5 views
1

IUserType을 통해 매핑되는 엔티티 컬렉션을 가질 수 있습니까? 예를 들어 : <property에 IUserType 매핑을 적용하기 위해 사용되는IUserType 인스턴스 모음을 가질 수 있습니까?

class Foo 
{ 
    public int Id { get; set; } 
    public ISet<Special> Items { get; set; } 
} 

class Special 
{ 
    public Special(string columnValue) 
    { 
     _val = columnValue; 
    } 

    public override string ToString() 
    { 
     return _val.TranformInInterestingWays(); 
    } 

    private string _val; 
} 

class SpecialUserTypeForMapping : IUserType 
{ 
    // assume that all the right stuff is here 
    // for using the non-default constructor on the way in 
    // and calling ToString() on the way out 
} 
내가 제대로 설명서를 읽고 있어요 경우

, 어느 것도 <set>, <one-to-many>, <many-to-many>도 <class> 요소는 "유형"속성을 지원합니다> 에스. 그럼 어떻게 매핑할까요?

답변

2

가장 편리한 솔루션은 지금처럼 <element> 요소를 사용하는 것 같다 : DB를 다른 푸 인스턴스를 가져

<class name="Foo" table="foos"> 
    <id name="Id" /> 
    <set name="Items" table="foo_special"> 
     <key column="fooId" /> 
     <element column="special_value" type="SpecialUserTypeForMapping" /> 
    </set> 
</class> 

아무 문제 없지만,에 대한 쿼리를 작성하는 것이 가능 여부를 명확하지 않다 내 시나리오의 요구 사항 인 special_value 열 This question은 그렇지 않음을 나타냅니다.

관련 문제