How to map HasMany Dictionary<string, string> ?
public class Team
{
public IDictionary<string, string> Members { get; set; }
}
Trying to map this as:
HasMany(team => team.Members)
.AsMap<string>("Name")
.Element("ProjectRole")
.Cascade.All();
produces the following error:
NHibernate.MappingException : Error mapping generic collection Xxx.Team.Members: expected 1 generic parameters, but the property type has 2
I feel I am doing something retarded here, having so many problems trying to map a simple IDictionary<string, string>. Using 1.0.0.593. Help!
Support Staff 2 Posted by James Gregory on 03 Aug, 2010 11:29 PM
As a user of our Dictionary support, you might be interested in our rework of this feature: Dictionary mapping redesign. We're working on simplifying the syntax, while making it more flexible at the same time.
You should just be able to do the following with the new design:
Excluding the
Index
andElement
calls would result in the columns beingKey
andValue
respectively.3 Posted by Paul Hatcher on 30 Aug, 2010 12:22 PM
Mapping a dictionary<string, string> was possible in 1.0 with the following syntax
HasMany(x => x.Properties)
However, this breaks under 1.1 and I can't find a working example - is this supported in 1.1 or do we need to wait on your new design?
Support Staff 4 Posted by James Gregory on 30 Aug, 2010 03:28 PM
Anything that worked in 1.0 should still work in 1.1. The new design is in master right now.
5 Posted by Mike Cole on 14 Oct, 2010 04:25 PM
Hi James,
I am unable to map this same scenario using the reworked method you supplied. I am using version 1.1.0.685.
In the reworked method I get the following error:
FluentNHibernate.Mapping.OneToManyPart' does not contain a definition for 'Index' and no extension method 'Index' accepting a first argument of type 'FluentNHibernate.Mapping.OneToManyPart' could be found (are you missing a using directive or an assembly reference?)
Am I missing something? Do I need a newer version?
Support Staff 6 Posted by James Gregory on 05 Nov, 2010 02:18 PM
Those methods are unavailable in the latest builds, that's what the "reworked" design did.
To quote myself:
7 Posted by Mike Cole on 05 Nov, 2010 02:28 PM
Ah, makes sense, sorry for the confusion.