How to map a dictionary to a complex key type (CultureInfo) using FluentNHibernate

I have a dictionary that I compile using Fluent NHibernate. The dictionary has a complex key type CultureInfo . My database cannot save this type, so I want to use its string representation.

In mappings other than dictionary mappings, I can successfully map CultureInfo -properties using a user type convention. Now I am wondering how to do this for wild mappings.

Here's the object containing the dictionary:

 public class MultilingualPhrase : Entity { private IDictionary<CultureInfo, string> languageValues; public virtual IDictionary<CultureInfo, string> LanguageValues { get { return languageValues; } } } 

And here is the redefinition of automatic display for the object:

 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:

Failed to convert parameter value from CultureInfo to string.

I know that NHibernate has a type of custom type for CultureInfo (I use it for mapping properties), but how to specify it in display override?

+6
source share
1 answer

This works great with FNH ClassMap (not sure about automatic mode) in NH 3.1 and FNH 1.2:

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

Source: https://habr.com/ru/post/886968/


All Articles