与NHibernate字符串映射集 [英] Mapping collection of strings with NHibernate

查看:268
本文介绍了与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

我如何能表映射到字符串的集合?

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天全站免登陆