为什么 Fluent NHibernate 忽略了我的约定?
我有一个约定 UserTypeConvention
其中 MyUserType : IUserType
其中 MyUserType
处理枚举类型 MyEnum
。我因此配置了 Fluent NHibernate
sessionFactory = Fluently
.Configure()
.Database(MsSqlConfiguration.MsSql2005.ConnectionString(
c => c.Is(connectionString))
)
.Mappings(
m => m
.FluentMappings
.AddFromAssemblyOf<A>()
.Conventions
.AddFromAssemblyOf<A>()
)
.BuildSessionFactory();
,其中 A
是与 UserTypeConvention
和 MyUserType
相同程序集中的类型。但是,Fluent NHibernate 不会将 MyUserType
应用于我的域对象上 MyEnum
类型的属性。相反,它将 FluentNHibernate.Mapping.GenericEnumMapper
到底是怎么回事?
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();
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.
What is going on?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
现在我已经解决了这个问题:
我认为这应该是完全没有必要的。如果有人告诉我这是 Fluent NHibernate 中的一个错误,那就没问题了。如果有人给我一个很好的理由,为什么 Fluent NHibernate 应该如此热衷于应用 GenericEnumMapper,那也是可以接受的。
For now I have solved this with:
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.好的,我尝试了以下方法,我认为它对您有用:
只需覆盖 MyEnumUserTypeConvention 类中的 Accept 方法,并且在其中不执行任何操作:
Ok i tried the following and I think it will works for you :
just overriede the Accept method in MyEnumUserTypeConvention class and do nothing inside it: