3

I'm using NHibernate and I map my objects directly with attributes. I've seen similar questions but most of the case people use mapping files... or they give answers with links that don't exist anymore :) For the following class, which attributes do I have to add for the property Table which is a IDictionary? I guess it's something like [Map] but with which attributes and/or elements? Where could I find some documentation?

[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; }

    // ...
}
pierroz
  • 7,653
  • 9
  • 48
  • 60

2 Answers2

3

after some tries it was not that difficult actually:

[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

pierroz
  • 7,653
  • 9
  • 48
  • 60
1

You probably won't like the answer but... the use of NHibernate.Mapping.Attributes it not recommended.

XML files are the most flexible and documented approach, FluentNHibernate is an alternative, and ConfORM is a totally different way to look at it.

Diego Mijelshon
  • 52,548
  • 16
  • 116
  • 154
  • @Diego: yeah I don't like your answer :) I'm joining the project and I can't unfortunately re-invent the wheel. I think I would prefer giving up the dictionary... – pierroz Mar 24 '10 at 08:11