2009-09-03 73 views
1

是否有可能通過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>元素支持 「type」 屬性爲用於IUserType映射應用於<property>秒。那麼我怎麼去做這件事呢?

回答

2

最有利的解決方案似乎是使用<element>元素,像這樣:

<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> 

檢索從數據庫中不同的Foo情況下是沒有問題的,但目前還不清楚是否有可能寫反查詢special_value列,這是我的場景中的要求。 This question似乎表明它不是。

相關問題