1

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

Community
  • 1
  • 1
smg
  • 1,096
  • 2
  • 11
  • 27
  • Seen this http://stackoverflow.com/questions/8345672/nhibernate-3-2-by-code-conformist-classmapping-for-a-dictionary-property ? – Rippo Jun 23 '14 at 15:59
  • Yes, and if replace `k.ManyToMany` with `k.Element` we have another error: `SELECT useroption0_.UserID as UserID0_, useroption0_.bool_column as bool_column0_, useroption0_.idx as idx0_ FROM UsersOptions useroption0_ WHERE useroption0_.UserID=?` I need entities in dict keys, so ManyToMany is right choose here (according to http://notherdev.blogspot.ru/2012/02/mapping-by-code-map.html). – smg Jun 23 '14 at 16:20

1 Answers1

0

OK, it is bug.

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

smg
  • 1,096
  • 2
  • 11
  • 27