2

How can I map these Entities using mapping-by-code:

public class Foo
{
    public virtual IDictionary<Bar, string> Bars { get; set; }
}

public class Bar
{
    public virtual int Id { get; set; }
    public virtual string Name { get; set; }
}

I found this thread, but it does not map an entity, only simple types. I tried many mappings, including automapping:

Map(x => x.Bars,
    m =>
    {
        m.Key(k => k.NotNullable(true));
        m.Cascade(Cascade.All);
    },

But most of them throw these two errors:

  1. Foreign key (Bars [idx])) must have same number of columns as the referenced primary key (Bars [FooId, idx]).
  2. An association from the table FoosToStrings refers to an unmapped class: System.String.

Any help will be highly appreciated. Thanks. :)

Community
  • 1
  • 1
Yogesh
  • 14,498
  • 6
  • 44
  • 69

1 Answers1

0

i think this should work

Map(x => x.Bars,
    entryMap => entryMap.Key(k => k.Column("foo_id")),
    keymap => keymap.ManyToMany(m => m.Column("bar_Id")),
    elementMap => elementMap.Element(m => m.Column("value")));
Firo
  • 30,626
  • 4
  • 55
  • 94