[英]NHibernate mapping an Dictionary to sql database
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. 我正在尝试使用NHibernate将字典映射到sql数据库,生成的映射对我来说还可以,但是如下所示的class属性却给我带来了问题。
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; 当我使用Microsoft的T4工具箱从类图生成数据时,出现以下错误;
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.. 现在已经在这个问题上停留了近两天。
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. 最后,我之所以能够解决这个问题,是因为出于多种原因我们为应用程序更改了设计,但是我仍然不知道如何将iDictionary映射到数据库。 So if someone has a solution, answers are welcome! 因此,如果有人有解决方案,欢迎回答! For know the problem is solved by a design modification 众所周知,问题是通过设计修改解决的
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. 据我所知,nHibernate通过动态组件映射字典,请参见http://ayende.com/Blog/archive/2009/04/11/nhibernate-mapping-ltdynamic-componentgt.aspx。但是,您应该注意“默认“ case”表示字典中每个条目的表中的一列。 Is this applicable ? 这适用吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.