なぜ流fluentなナイベラン酸は私の条約を無視しているのですか?
-
28-09-2019 - |
質問
コンベンションがあります UserTypeConvention<MyUserType>
どこ 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>
と MyUserType
. 。ただし、Fluent Nhibernateは適用されていません MyUserType
タイプのプロパティへ MyEnum
私のドメインオブジェクトに。代わりに、それは適用されています FluentNHibernate.Mapping.GenericEnumMapper<MyEnumType>
これらのプロパティに。
何が起こっている?
解決
今のところ、私はこれを解決しました:
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>();
}
}
これは完全に不必要であるべきだと思います。誰かが私にこれが流fluentなニベナートのバグであると言ったら、それは大丈夫だろう。誰かが私に流fluentなnhibernateが応募に非常に熱心であるべき正当な理由を与えた場合 GenericEnumMapper
それも受け入れられます。
他のヒント
わかりました、私は次のことを試しました、そして私はそれがあなたのために働くと思います:
MyEnumusertypeConventionクラスのAccept Methodを過剰に実行し、その中に何もしません。
public class MyEnumUserTypeConvention : UserTypeConvention<MyEnumUserType>
{
public override void Accept(FluentNHibernate.Conventions.AcceptanceCriteria.IAcceptanceCriteria<FluentNHibernate.Conventions.Inspections.IPropertyInspector> criteria)
{
///Do nothing
}
}
所属していません StackOverflow