Search code examples
nhibernatenhibernate-mapping-by-code

NHibernate mapping Dictionary by code


How to map this Dictionary using mapping-by-code:

public class User
{
    public virtual Dictionary<Option, bool> Options { get; set; } }
}

Database looks like this:

User     UserOptions    Option
---      ---            ---
Id       Id             Id
         UserID
         OptionID
         bool_column

I tried that mapping (looking here):

Map(x => x.Dictionary, 
m =>
{
    m.Key(k => k.Column("UserID"));
    m.Table("UserOptions");
},
k => k.ManyToMany(m =>
{
    m.Column("OptionID");
}),
v => v.Element(m => 
{
    m.Column("bool_column");
})
);

But there is an error: An association from the table UserOptions refers to an unmapped class: System.Boolean


Solution

  • OK, it is bug.

    Solved by using xml-mapping for User, and adding configuration.AddXmlFile("Mappings/User.hbm.xml");