0

I've asked this elsewhere and not got any sensible reply

I'm trying to map an IDictionary. I have this mapping:

<class name="MyProject.Item, MyProject" table="Item"> 
<...>
<map name="Properties" access="property" table="ItemProperties" lazy="false"> 
  <key column="ItemID" /> 
  <index column="Idx" type="int" /> 
 <element column="Value" type="System.Boolean, mscorlib"/> 
</map> 

I can persist data, but when the data is retrieved I get an nHibernate exception: {"The value "0" is not of type "Project.PropertyType" and cannot be used in this generic collection. Parameter name: key"}

So it can't map to the enum, but why ? if I have a regular property that uses an enum, it works fine.

Is what I'm trying to do even possible ? I can't find much info on doing this.

1 Answer 1

0

Your mapping shows the key as an integer, not as an enum. To map the enum properly, use type="MyProject.Project.PropertyType, MyProject".

However, normally for an enum the best approach is to leave the type information out of the mapping file altogether and let NHib pick it up through reflection. My reading of the NHib source implies that if you are mapping into a generic IDictionary<K,V> then NHib should pick up the exact type of your key via reflection. IOW you still should be able to leave out the type attribute.

1
  • Thanks, I'll experiment with removing the type info, I'm having to use ActiveRecord as an extra layer on top which makes things a bit more complicated.
    – Mark
    Oct 28, 2009 at 8:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.