私は多くの異なるマッピング設定を試みましたが、例外の生成や間違ったレコードの作成/更新を続けています。Fluentを使ったNHibernateの参照されたサブクラスのマッピング
例外
- テーブルにID列の明示的な値を挿入することはできません
- 組合-サブクラスマッピングにID列キー生成を使用することはできません
- ヌルIDクラスXXXのために生成
保存している地図を持っていると、次の問題が発生します
データベースにレコードを挿入して正常に更新しましたが、これらのレコードには適切なIDがありません。それらはすべてidのために0を持っているので、同じレコードを繰り返し更新するだけです。
問題私はSubclassMap
インタフェースIRequest
しようとしています
解決しようとしています。このインターフェイスは、別のクラスAbstractWorkflowRequestInformation
のプロパティとして使用されます。親クラスを保存するときは、参照先のIRequest
を適切なサブクラステーブルに保存します。これは例外Cannot insert explicit value for identity column in table
を生成する私の現在のマッピングです。私は、これらの2つのクラスの関係をマッピングする方法で何かを微調整していると確信しています。私は間違って何をしていますか?私の地図は以下の通りです。
IRequestMap
public class IRequestMap : ClassMap<IRequest>
{
public IRequestMap()
{
Id(x => x.WorkflowRequestInformation)
.GeneratedBy.Foreign("AbstractWorkflowRequestInformation");
UseUnionSubclassForInheritanceMapping();
}
}
public class PlanRequestMap : SubclassMap<PlanRequest>
{
public PlanRequestMap()
{
Table("plan_request");
// specific to PlanRequest property mappings and references
}
}
public class BnjRequestMap : SubclassMap<BnjRequest>
{
public BnjRequestMap()
{
Table("scratchdb.guest.bnj_request");
// specific to BnjRequest property mappings and references
}
}
AbstractWorkflowRequestInformationMap
public class AbstractWorkflowRequestInformationMap :
ClassMap<AbstractWorkflowRequestInformation>
{
public AbstractWorkflowRequestInformationMap()
{
Table("workflow_request_information");
Id(x => x.Id)
.Column("workflow_request_information_id")
.GeneratedBy.Identity();
// more property mappings and references
References(x => x.SuperDuperRequest, "workflow_request_information_id")
.Class<IRequest>().Unique().Cascade.All();
// more property mappings and references
}
}
完全な例外は、どのテーブルエンティティがどのエンティティを挿入しているかなどを確認するのに役立ちます。 – Firo