views:

155

answers:

2

I've got the a class created in code an added it to my class diagram. The class diagram is used by a text template generatorto generate code from this class diagram. I'm trying to map a dictionary to an sql database with NHibernate, the generated mapping looks ok to me, but the class property as shown below is giving me problems.

This is the property;

[Map(2, Name = "QuantityIdentifiers", Table = "PluginProduct_QuantityIdentifiers")]
        [Key(3, Column = "ItemId")]
        [Index(4, Column = "Id", Type = "string")]
        [Element(5, Column = "QuantityType", Type = "string")]
        public virtual IDictionary<string, string> QuantityIdentifiers
        {
            get { return _identifiersVariants; }
            set { _identifiersVariants = value; }
        }

This is the part of the mapping which is also being generated within the application i'm working on;

<map name="QuantityIdentifiers" table="PluginProduct_QuantityIdentifiers" cascade="all">
      <index column="Id" type="string" />
      <element column="Type" type="String" />
    </map>

When i'm using the T4 toolbox from Microsoft to generate from the class diagram i'm getting the following error;

Error 235 Running transformation: System.InvalidOperationException: Sequence contains no elements
   at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
   at Microsoft.VisualStudio.TextTemplating6FC9B85C3A64B0406665113D095DEF7E.GeneratedTextTransformation.controllerTemplate.TransformText() in c:\Projects\site\PluginGenerator\controllerTemplate.tt:line 722
   at T4Toolbox.Template.Transform()
   at T4Toolbox.Template.Render()
   at Microsoft.VisualStudio.TextTemplating6FC9B85C3A64B0406665113D095DEF7E.GeneratedTextTransformation.generateFiles.RunCore() in c:\Projects\site\CMS.PluginGenerator\generateFiles.tt:line 74
   at T4Toolbox.Generator.Run()
   at Microsoft.VisualStudio.TextTemplating6FC9B85C3A64B0406665113D095DEF7E.GeneratedTextTransformation.TransformText() in c:\Projects\site\Product\Generator\PluginGenerator.tt:line 18
   at Microsoft.VisualStudio.TextTemplating.TransformationRunner.RunTransformation(TemplateProcessingSession session, String source, ITextTemplatingEngineHost host, String& result)  1 1 

I hope someone can help me explaining and finding out where this error is coming from. Been stuck on this problem for nearly two days now..

A: 

In the end i was able to work around it because we changed the design for the application for several reasons, nevertheless i still don't know how to map an iDictionary to the database. So if someone has a solution, answers are welcome! For know the problem is solved by a design modification

Rob
A: 

As far as I know nHibernate map the dictionary through the dynamic component see http://ayende.com/Blog/archive/2009/04/11/nhibernate-mapping-ltdynamic-componentgt.aspx However you should be aware that the "default" case imply a column in the table for each entry in the dictionary. Is this applicable ?

mCasamento