本文介绍了如何映射使用FluentNHibernate一个复杂的密钥类型字典(的CultureInfo)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的字典,我用流利的NHibernate正在映射。这本字典有一个复杂的密钥类型的CultureInfo 。我的数据库不能存储的类型,所以我想用一个字符串,再它的presentation。

I have dictionary which I'm mapping using Fluent NHibernate. The dictionary has a complex key type CultureInfo. My database can't store that type so I want to use a string representation of it.

在映射比字典映射等,我可以成功地映射的CultureInfo -properties使用用户类型的约定。现在我不知道该怎么做了dicationary映射。

In mappings other than dictionary mappings, I can successfully map CultureInfo-properties using a user type convention. Now I wonder how to do it for dicationary mappings.

下面是包含词典中的实体:

Here's the entity that contains the dictionary:

public class MultilingualPhrase : Entity
{
    private IDictionary<CultureInfo, string> languageValues;

    public virtual IDictionary<CultureInfo, string> LanguageValues
    {
        get
        {
            return languageValues;
        }
    }
}

和这里的自动映射倍率实体:

And here's the auto mapping override for the entity:

public void Override(AutoMapping<MultilingualPhrase> mapping)
{
    mapping
        .HasMany(n => n.LanguageValues)
        .Access.ReadOnlyPropertyThroughCamelCaseField()
        .AsMap<string>("CultureName")
        .Element("Phrase")
        .Table("MultilingualPhraseValues");
}

这个映射(显然)导致以下错误:

This mapping (obviously) causes the following error:

无法参数值转换一个CultureInfo为String。

我知道NHibernate的有一个类型的自定义类型实施的CultureInfo (我用它映射属性),但我怎么在我的映射覆盖指定呢?

I know NHibernate has a type custom type implementation for CultureInfo (I'm using it for mapping properties) but how do I specify it in my mapping override?

推荐答案

这正常工作与FNH ClassMap(不知道自动映射)在新罕布什尔州3.1和1.2 FNH:

This works fine with FNH ClassMap (not sure about automapping) in NH 3.1 and FNH 1.2:

HasMany(n => n.LanguageValues)
    .Access.ReadOnlyPropertyThroughCamelCaseField()
    .AsMap<CultureInfo>("CultureName")
    .Element("Phrase")
    .Table("MultilingualPhraseValues");

这篇关于如何映射使用FluentNHibernate一个复杂的密钥类型字典(的CultureInfo)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 17:32