views:

200

answers:

2

What is the best way of mapping a simple Dictionary property using Fluent NHibernate?

+2  A: 

Hello

to map a list as a dictionary

HasMany(x => x.Customers) .AsMap();

I have not used it... so cannot give an example.

Have look at the wiki Cached version of the page, Actual page, I have geiven the cached version of the page as the site seems to be down

dbones
A: 

Using a simple class relationship such as the following:

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

public class Bar {
    public virtual string Type { get; set; }
    public virtual int Value { get; set; }
}

You can map this with Fluent NHibernate in this way:

mapping.HasMany(x => x.Bars)
       .AsMap(x => x.Type);

Where Bar.Type is used as the index field into the dictionary.

JD Courtoy