流利的 NHibernate AutoMap CultureInfo
Fluent NHibernate AutoMap CultureInfo
我在使用 CultureInfo 属性 自动映射实体时遇到问题,当我尝试构建 SessionFactory 时它抛出异常并出现以下错误:
"An association from the table ExampleClass refers to an unmapped class: System.Globalization.CultureInfo"
通话:
var configuration = new Configuration();
var sessionFactory = Fluently.Configure(configuration)
.Mappings(m =>
m.AutoMappings.Add(AutoMap.AssemblyOf<ExampleClass>(
new DefaultAutomappingConfiguration()
))
)
.BuildSessionFactory();
示例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; }
}
如果我只是导出映射然后它会正确显示映射,看起来 System.Globalization.CultureInfo 未包含在自动映射策略中。
手动覆盖 class 的映射时有效。Override(mapping => mapping.Map(x => x.Culture)).
有谁知道如何防止这种情况发生?或者自动映射所有 CultureInfo 的?
要使用 NHibernate 对 CultureInfo
的映射支持(在那里,请参阅 https://github.com/nhibernate/nhibernate-core/blob/c85d038dce8ba87bd3f4de2458b4ef6e2497f7f8/src/NHibernate/Type/CultureInfoType.cs),您需要通过以下约定告诉 Fluent NHibernate 您想要使用它:
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");
}
}
我在使用 CultureInfo 属性 自动映射实体时遇到问题,当我尝试构建 SessionFactory 时它抛出异常并出现以下错误: "An association from the table ExampleClass refers to an unmapped class: System.Globalization.CultureInfo"
通话:
var configuration = new Configuration();
var sessionFactory = Fluently.Configure(configuration)
.Mappings(m =>
m.AutoMappings.Add(AutoMap.AssemblyOf<ExampleClass>(
new DefaultAutomappingConfiguration()
))
)
.BuildSessionFactory();
示例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; }
}
如果我只是导出映射然后它会正确显示映射,看起来 System.Globalization.CultureInfo 未包含在自动映射策略中。
手动覆盖 class 的映射时有效。Override(mapping => mapping.Map(x => x.Culture)).
有谁知道如何防止这种情况发生?或者自动映射所有 CultureInfo 的?
要使用 NHibernate 对 CultureInfo
的映射支持(在那里,请参阅 https://github.com/nhibernate/nhibernate-core/blob/c85d038dce8ba87bd3f4de2458b4ef6e2497f7f8/src/NHibernate/Type/CultureInfoType.cs),您需要通过以下约定告诉 Fluent NHibernate 您想要使用它:
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");
}
}