views:

30

answers:

1

In NHibernate you can map generics like this

<class name="Units.Parameter`1[System.Int32], Units" table="parameter_int"  >
</class>

But how can I map a class like this?

Set<T> where T is a Parameter<int> like this Set<Parameter<int>>

My mapping hbm.xml looking like this fails

<class name="Set`1[[Units.Parameter`1[System.Int32], Units]],Units"  table="settable"/> 

I simplified my mappings a little to get my point accross very clearly. Basically I want NHibernate to map generic class which has has generic type parameter.

Want I understand from googling around is that NHibernate is not able to parse the name to the correct type in TypeNameParser.Parse() which result in the following error when adding the mapping to the configuration

System.ArgumentException: Exception of type 'System.ArgumentException' was thrown. Parameter name: typeName@31

Anybody found a way around this limitation?

A: 

I think you'll have to map it as a custom type. See this article and google for IUserType.

Jamie Ide
Seems to me IUserType is about creating custom handlers for properties not for classmappings. I cannot use type= on my class declaration
Gluip
I misunderstood your question. You're doing something like this: http://ayende.com/Blog/archive/2007/11/14/NHibernate-and-Generic-Entities.aspx which I didn't know was possible. Note that the author (Ayende) closes with "In short, it is possible, but don't do it."
Jamie Ide
You're right. Unfortunately I don't have the luxury of creating specific classes for my Set<T> because I don't control what T is going to be. I am developing a framework and I don't want to restrict the Set<T> so that T is non-generic. So I'll have to revert my collection to a non-generic version. Thanks for your help.
Gluip