2010-03-23 50 views
2

我正在使用NHibernate,我直接用屬性映射我的對象。我見過類似的問題,但大多數情況下人們使用映射文件......或者他們給出的答案不再存在的鏈接:)對於以下類,必須爲屬性Table添加哪些屬性一個IDictionary?我想這是像[地圖],但具有哪些屬性和/或元素?我在哪裏可以找到一些文件?我應該在我的類中使用哪種NHibernate.Mapping.Attribute來映射字典?

[Class(Table = "SpecificitySets", Name = "ZslSpecificityTable")] 
public class SpecificityTable 
{ 
    [Id(0, TypeType = typeof(ulong), Name = "Id")] 
    [Generator(1, Class = "native")] 
    public uint Id 

    [Map(Name = "specificityMapping", Table = "SpecificityMapping")] 
    // and then ?? 
    public virtual IDictionary<string, double> Table { get; private set; } 

    // ... 
} 

回答

3

一些嘗試後,這是並不難實際上是:

[Class(Table = "SpecificitySets", Name = "ZslSpecificityTable")] 
public class SpecificityTable 
{ 
    [Id(0, TypeType = typeof(ulong), Name = "Id")] 
    [Generator(1, Class = "native")] 
    public uint Id 

    [Map(1, Name = "Table", Table = "SpecificityMapping")] 
    [Key(1, Column = "SpecTableId")] 
    [Index(3, Column = "Term", Type="string")] 
    [Element(4, Column = "Value", Type="double")] 
    public virtual IDictionary<string, double> Table { get; private set; } 

    // ... 
} 
1

你可能會不喜歡的答案。但它不推薦使用NHibernate.Mapping.Attributes的。

XML文件是最靈活和最成文的方法,FluentNHibernate是一種替代方法,ConfORM是一個完全不同的方式來看待它。

+0

@Diego:是的,我不喜歡你的答案:)我參加這個項目,我不能不幸重新發明輪子。我想我寧願放棄字典... – PierrOz 2010-03-24 08:11:17

相關問題