使用 C# 将字典映射到休眠映射

问题描述 投票:0回答:1

我得到了以下 C# 课程:

public class SomeClass()
{
   public SomeClass()
   public Guid Id;
   public virtual Dictionary<string,int> DictionaryInClass;
   public virtual string Description;

}

在休眠映射中:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
                   assembly="..."
                   namespace="...">
  <class name="SomeClass" abstract="true" table="SomeClass">
 <property name="Id" />
 <property name="Description" />
 <map> or <list>
</hibernate-mapping>

我应该使用集合还是地图?具体如何?像这样的东西,但我收到错误,因为没有正确类型的属性和元素,如果尝试使用复合元素,它会抱怨没有“System.Collections.Generic.Dictionary”的类。

<map name="DictionaryInClass" table="SomeClass_separateTableForDict">
  <key column="SomeClassId" not-null="true" />
   <index column="key" /> <!-- should there be index? -->
   <property="value" /> <!-- kinda lost here -->
</map>
c# dictionary hibernate-mapping
1个回答
0
投票

最终得到以下解决方案:

<map name="DictionaryInClass" table="SomeClass_separateTableForDict">
   <key column="SomeClassId" /> <!-- This is the key to SomeClass -->
   <map-key column="key_column" /> <!-- This is the key in the dictionary with type string -->
   <element="value_column" /> <!-- This is the value in the dictionary -->
</map>
© www.soinside.com 2019 - 2024. All rights reserved.