使用 NHibernate 映射字符串集合 [英] Mapping collection of strings with NHibernate

查看:22
本文介绍了使用 NHibernate 映射字符串集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有属性 IList 的域类,我想将其映射到具有单个数据值的表(即它有一个 ID,域实体的外键 ID)表和一个 varchar 数据列).

I have a domain class with a property IList<string> that I want to map to a table with a single data value (i.e. it has an ID, a foreign key ID to the domain entity table, and a varchar data column).

我不断收到错误:

关联引用未映射的类:System.String

Association references unmapped class: System.String

如何将表映射到字符串集合?

How can I map a table to a collection of strings?

推荐答案

我刚刚遇到了类似的情况;我发现确实可以映射字符串集合.请注意,您必须将这些字符串映射为值对象.

I just ran into a similar situation; and I found that it is indeed possible to map a collection of strings. Note that you'll have to map those strings as value objects.

这就是我所拥有的:

public class Chapter
{
    private ISet<string> _synonyms = new HashedSet<string>();

    public ReadOnlyCollection<string> Synonyms
    {
       get { return new List<string>(_synonyms).AsReadOnly(); }
    }
}

映射:

<class name="Chapter" table="Chapter">
   <set name="Synonyms" table="ChapterSynonyms">
       <key column="ChapterId" />
       <element column="ChapterCode" type="string" />
   </set>
</class>

这篇关于使用 NHibernate 映射字符串集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆