Which NHibernate.Mapping.Attributes should I use in my class to map a dictionary?
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(ul开发者_高级运维ong), 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; }
// ...
}
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
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.
精彩评论