1
votes

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

1
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 notherdev.blogspot.ru/2012/02/mapping-by-code-map.html). - smg

1 Answers

0
votes

OK, it is bug.

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