2009-05-07 14 views
1

NHibernateでFluent NHibernate設定を使用して、null可能な列挙型を永続化できませんでした。 NHibernateのは、列挙型の文字列表現を保存しようと、私はエラーNHibernateのnullable enumをどのようにマップできますか?

System.Data.SqlClient.SqlException: Conversion failed when converting the 
nvarchar value 'VGS' to data type tinyint. 

プロパティが

public virtual CostContributor? ReplacementContributor { get; private set; } 

として定義され、マッピングが私はすべて試した

Map(x => x.ReplacementContributor).CustomTypeIs(typeof(CostContributor?)); 

あり得ますCustomTypeIsとCustomSqlTypeIsの組み合わせ(intの代用を含む)またはバイト? CostContributorのための?、しかし何も働いていない。私がnullableでない型にするとうまくいきます。

NHibernateにnull許容列挙型をマップすることは可能ですか?またはこれはNHibernateのバグまたはサポートされていない機能ですか?

私がこの作業を行うことができない場合は、回避策として列挙型に未定義の値を追加します。

がCostContributorEntityというクラスを追加します。

答えて

2

これはbug and it's been fixedでした。

+0

ここで提供されるリンクは死んでいますが、質問はhttp://stackoverflow.com/questions/13881971/fluent-nhibernate-mapping-nullable-enumで回答されています – bunggo

0

正しくが、ここでそれを行う方法をわからないが、別の回避策です。クラスは、CostContributor型のproperty:IDのみを持ちます。必要がない限り、実際のテーブルを作成する必要はありません。

消費するクラスでReplacementContributorをタイプCostContributorEntityに変更し、というようにマップします。参照(x => x.ReplacementContributor);

Session.Load(CostContributor.Blahblah1)を使用して、ReplacementContributorに割り当てることができるCostContributorEntityのインスタンスを作成します。

関連する問題