为什么Fluent NHibernate忽略了我的惯例? [英] Why is Fluent NHibernate ignoring my convention?

查看:112
本文介绍了为什么Fluent NHibernate忽略了我的惯例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个约定 UserTypeConvention< MyUserType> 其中 MyUserType:IUserType 其中 MyUserType 处理枚举类型 MyEnum 。我已经配置了流利的NHibernate

I have a convention UserTypeConvention<MyUserType> where MyUserType : IUserType where MyUserType handles an enum type MyEnum. I have configured Fluent NHibernate thusly

sessionFactory = Fluently
                .Configure()
                .Database(MsSqlConfiguration.MsSql2005.ConnectionString(
                    c => c.Is(connectionString))
                )
                .Mappings(
                    m => m
                            .FluentMappings
                                .AddFromAssemblyOf<A>()
                            .Conventions
                                .AddFromAssemblyOf<A>()
                )
                .BuildSessionFactory();

其中 A 是一种类型汇编为 UserTypeConvention< MyUserType> MyUserType 。但是,Fluent NHibernate不会将 MyUserType 应用于域对象上的 MyEnum 类型的属性。相反,它正在向这些属性应用 FluentNHibernate.Mapping.GenericEnumMapper< MyEnumType>

where A is a type in the same assembly as UserTypeConvention<MyUserType> and MyUserType. However, Fluent NHibernate is not applying MyUserType to properties of type MyEnum on my domain objects. Instead, it is applying FluentNHibernate.Mapping.GenericEnumMapper<MyEnumType> to these properties.

发生了什么?

推荐答案

现在我已经解决了:

public class MyEnumUserTypeConvention : UserTypeConvention<MyEnumUserType> {
    public override void Accept(IAcceptanceCriteria<IPropertyInspector> criteria) {
        // Fluent NHibernate is too eager in applying GenericEnumMapper
        // so our criteria is that it is already applied this type
        criteria.Expect(x => x.Type == typeof(GenericEnumMapper<MyEnum>));
    }

    public override void Apply(IPropertyInstance instance) {
        // we override Fluent NHibernate's application of GenericEnumMapper
        instance.CustomType<MyEnumUserType>();
    }
}

我认为这是彻底不必要的。如果有人告诉我,这是一个流利的NHibernate的错误,那就好了。如果有人给了我一个很好的理由,为什么Fluent NHibernate应该如此渴望应用 GenericEnumMapper ,这也是可以接受的。

I think this should be thoroughly unnecessary. If someone told me this were a bug in Fluent NHibernate, that'd be fine. If someone gave me a good reason why Fluent NHibernate should be so eager in applying GenericEnumMapper that would be acceptable too.

这篇关于为什么Fluent NHibernate忽略了我的惯例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆