I have an issue where i am AutoMapping an Entity with a CultureInfo property, when i try to build the SessionFactory it throws exception with following error: "An association from the table ExampleClass refers to an unmapped class: System.Globalization.CultureInfo"
Call:
var configuration = new Configuration();
var sessionFactory = Fluently.Configure(configuration)
.Mappings(m =>
m.AutoMappings.Add(AutoMap.AssemblyOf<ExampleClass>(
new DefaultAutomappingConfiguration()
))
)
.BuildSessionFactory();
Example class:
public class ExampleClass
{
public virtual int Id { get; set; }
public virtual int ExampleClassId { get; set; }
public virtual string LineOne { get; set; }
public virtual CultureInfo Culture { get; set; }
}
If i just export the mapping then it shows the mapping correctly, it looks like the System.Globalization.CultureInfo isn't included in the automapping strategy.
It works when manually override the mapping for the class .Override(mapping => mapping.Map(x => x.Culture)).
Does anyone know how to prevent this? Or Automatically map all CultureInfo's?
To use NHibernate's mapping support for CultureInfo
(which is there, see https://github.com/nhibernate/nhibernate-core/blob/c85d038dce8ba87bd3f4de2458b4ef6e2497f7f8/src/NHibernate/Type/CultureInfoType.cs), you'll need to tell Fluent NHibernate you want to use it by means of the following convention:
using System.Globalization;
using FluentNHibernate.Conventions;
using FluentNHibernate.Conventions.AcceptanceCriteria;
using FluentNHibernate.Conventions.Inspections;
using FluentNHibernate.Conventions.Instances;
public class CultureInfoConvention : IUserTypeConvention
{
public void Accept(IAcceptanceCriteria<IPropertyInspector> criteria)
{
criteria.Expect(n => n.Property.PropertyType == typeof(CultureInfo));
}
public void Apply(IPropertyInstance instance)
{
instance.CustomType("CultureInfo");
}
}