[fluent-nhib] How to map HasMany Dictionary<string, string> ?

1,101 views
Skip to first unread message

Richard Dingwall

unread,
Apr 22, 2010, 3:12:02 PM4/22/10
to Fluent NHibernate
public class Team
{
public IDictionary<string, string> Members { get; set; }
}

Trying to map this as:

HasMany<string>(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!

--
You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
To post to this group, send email to fluent-n...@googlegroups.com.
To unsubscribe from this group, send email to fluent-nhibern...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/fluent-nhibernate?hl=en.

moebius206

unread,
Apr 22, 2010, 6:30:35 PM4/22/10
to Fluent NHibernate
Yeah, there's some extreme weirdness with Intellisense when trying to
specify the index and element columns.

Here's an example:

HasMany(x => x.Members)
.AsMap<string>(index =>
index.Column("membersKey").Type<string>(),
element =>
element.Column("membersValue").Type<string>())
.Cascade.All();

Hope this helps.

moebius206

unread,
Apr 22, 2010, 6:31:41 PM4/22/10
to Fluent NHibernate
I should mention that Intellisense will say there's an error with that
example until it's all typed out, where it's magically accepted.
Ignore intellisense and follow the example.

Richard Dingwall

unread,
Apr 23, 2010, 4:50:54 AM4/23/10
to Fluent NHibernate
On Apr 22, 11:30 pm, moebius206 <nwe...@gmail.com> wrote:
> Yeah, there's some extreme weirdness with Intellisense when trying to
> specify the index and element columns.
>
> Here's an example:
>
> HasMany(x => x.Members)
>                 .AsMap<string>(index =>
> index.Column("membersKey").Type<string>(),
>                                element =>
> element.Column("membersValue").Type<string>())
>                 .Cascade.All();
>
> Hope this helps.

Hmm, still doesn't work:

NHibernate.MappingException : Error mapping generic collection
Xxx.Team.Members: expected 1 generic parameters, but the property type
has 2
at NHibernate.Mapping.Collection.CheckGenericArgumentsLength(Int32
expectedLength)
at NHibernate.Mapping.Bag.get_DefaultCollectionType()
at NHibernate.Mapping.Collection.get_CollectionType()
at NHibernate.Mapping.Collection.get_Type()
at NHibernate.Tuple.PropertyFactory.BuildStandardProperty(Property
property, Boolean lazyAvailable)
at NHibernate.Tuple.Entity.EntityMetamodel..ctor(PersistentClass
persistentClass, ISessionFactoryImplementor sessionFactory)
at
NHibernate.Persister.Entity.AbstractEntityPersister..ctor(PersistentClass
persistentClass, ICacheConcurrencyStrategy cache,
ISessionFactoryImplementor factory)
at
NHibernate.Persister.Entity.SingleTableEntityPersister..ctor(PersistentClass
persistentClass, ICacheConcurrencyStrategy cache,
ISessionFactoryImplementor factory, IMapping mapping)
at
NHibernate.Persister.PersisterFactory.CreateClassPersister(PersistentClass
model, ICacheConcurrencyStrategy cache, ISessionFactoryImplementor
factory, IMapping cfg)
at NHibernate.Impl.SessionFactoryImpl..ctor(Configuration cfg,
IMapping mapping, Settings settings, EventListeners listeners)
at NHibernate.Cfg.Configuration.BuildSessionFactory()
...

I pasted your code directly... why is it trying to map it as a bag?

Rich

Richard Dingwall

unread,
Apr 23, 2010, 4:56:32 AM4/23/10
to Fluent NHibernate
Sorry, just realised the exception was actually on another entity
where I hadn't applied the fix yet... your code worked great!

Thanks heaps,

Paul Batum

unread,
Apr 25, 2010, 10:13:32 AM4/25/10
to fluent-n...@googlegroups.com
I'm glad I'm not the only one that has problems with the intellisense for that overload. Its really weird how it doesn't like it.

lgloria

unread,
Apr 27, 2010, 4:08:04 PM4/27/10
to Fluent NHibernate
I can't seem to get this to work. I still get the same error message:
System.ArgumentException: The type or method has 2 generic
parameter(s), but 1 generic argument(s) were provided. A generic
argument must be provided for each generic parameter.

I'm using Sharp Architecture v1.0. I tried updating to v1.5 but I'm
still getting the same error.

On Apr 25, 10:13 am, Paul Batum <paul.ba...@gmail.com> wrote:
> I'm glad I'm not the only one that has problems with the intellisense for
> that overload. Its really weird how it doesn't like it.
>
> On Fri, Apr 23, 2010 at 6:56 PM, Richard Dingwall <rdingw...@gmail.com>wrote:
>
>
>
>
>
> > Sorry, just realised the exception was actually on another entity
> > where I hadn't applied the fix yet... your code worked great!
>
> > Thanks heaps,
>
> > Rich
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Fluent NHibernate" group.
> > To post to this group, send email to fluent-n...@googlegroups.com.
> > To unsubscribe from this group, send email to
> > fluent-nhibern...@googlegroups.com<fluent-nhibernate%2Bunsubscr­i...@googlegroups.com>
> > .
> > For more options, visit this group at
> >http://groups.google.com/group/fluent-nhibernate?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
> To post to this group, send email to fluent-n...@googlegroups.com.
> To unsubscribe from this group, send email to fluent-nhibern...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/fluent-nhibernate?hl=en.- Hide quoted text -
>
> - Show quoted text -

moebius206

unread,
Apr 27, 2010, 6:46:13 PM4/27/10
to Fluent NHibernate
Make sure you're running the current Fluent NHibernate libraries -
just go ahead and download the latest and swap them out. For sure,
the posted code works. Also, as stated, Intellisense will recognize
it as an error until you get all of the code typed out - so if that's
what you're going by, ignore it. If you're getting a compile-time
error, then you must be using a FNH library prior to 1.0.

- nick
> > For more options, visit this group athttp://groups.google.com/group/fluent-nhibernate?hl=en.-Hide quoted text -
>
> > - Show quoted text -
>
> --
> You received this message because you are subscribed to the Google Groups "Fluent NHibernate" group.
> To post to this group, send email to fluent-n...@googlegroups.com.
> To unsubscribe from this group, send email to fluent-nhibern...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/fluent-nhibernate?hl=en.

Asbjørn Ulsberg

unread,
May 13, 2010, 5:49:35 PM5/13/10
to fluent-n...@googlegroups.com, Paul Batum
I think the syntax for .AsMap() is really obscure and disregarding
intellisense, it's not intuitive in any way however you look at it. Could
it perhaps be improved/simplified in a way to make intellisense not go
haywire and at the same time be a bit more intuitive?


-Asbjørn


On Sun, 25 Apr 2010 16:13:32 +0200, Paul Batum <paul....@gmail.com>
wrote:

> I'm glad I'm not the only one that has problems with the intellisense for
> that overload. Its really weird how it doesn't like it.
>
> On Fri, Apr 23, 2010 at 6:56 PM, Richard Dingwall
> <rdin...@gmail.com>wrote:
>
>> Sorry, just realised the exception was actually on another entity
>> where I hadn't applied the fix yet... your code worked great!
>>
>> Thanks heaps,
>>
>> Rich
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups
>> "Fluent NHibernate" group.
>> To post to this group, send email to fluent-n...@googlegroups.com.
>> To unsubscribe from this group, send email to
>> fluent-nhibern...@googlegroups.com<fluent-nhibernate%2Bunsu...@googlegroups.com>
>> .

James Gregory

unread,
May 14, 2010, 8:39:41 AM5/14/10
to fluent-n...@googlegroups.com
Maps and collections in general are on our roadmap, we're definitely aware of how horrible they are. It won't make 1.1, as there'll be pretty significant work needed, but 1.2 or 2.0 will definitely have them improved.

2010/5/13 Asbjørn Ulsberg <asbj...@gmail.com>

Asbjørn Ulsberg

unread,
May 16, 2010, 4:06:49 PM5/16/10
to fluent-n...@googlegroups.com, James Gregory
Awesome! It would be cool if you could "beta test" the new collection
interfaces with the community before it's written in stone. :)


-Asbjørn
>>>> <fluent-nhibernate%2Bunsu...@googlegroups.com<fluent-nhibernate%252Buns...@googlegroups.com>
Reply all
Reply to author
Forward
0 new messages