別のコンテキストで継承されているコンテキストでエンティティ構成を変更/置換することは可能ですか?
例: Framework というソリューションの Data.Access というプロジェクトに Context があります。その OnModelCreating 関数は、次のようにエンティティ構成を追加します。
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// TestEntityConfiguration is the configuration of an entity named TestEntity in the Framework solution
modelBuilder.Configurations.Add(new TestEntityConfiguration());
// multiple other configurations...
}
FrameworkConsumer と呼ばれる別のソリューションには、Framework ソリューションの Data.Access から Context を拡張する Context クラスを持つ Local.Data.Access プロジェクトがあります。その OnModelCreating 関数は次のようになります。
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
// Adds all the configurations from the Context in Data.Access in the Framework solution
base.OnModelCreating(modelBuilder);
// Other configurations local to the extended context go here...
}
私の質問はこれです。FrameworkConsumer ソリューションの Local.Data.Access プロジェクトで、追加の構成設定または TestEntity の別の構成を追加したい場合、これはどのように達成できますか? 別の構成を追加しようとしましたが、このエンティティ (TestEntity) が既に構成されているというエラーが表示されます。今のところ、構成を追加する私の解決策は、Local.Data.Access Context クラスの Dispose 関数で Database.ExecuteSqlCommand を使用することでした。エレガントではありませんが、機能します。アイデア/アドバイスをいただければ幸いです。
ありがとう