最適な解決策がわからない問題があります。うまくいけば、ここの誰かが助けてくれる=)
私が解決しようとしているのは、システム、人、および組織でユーザーをタイプする必要があることです。2 つの共有ログイン テーブルが必要です (つまり、ユーザーは自分がどのタイプのユーザーであるかをおそらく知らないでしょう。ユーザー名とパスワードに関連しているだけです)。そこで、ユーザー名とパスワード用のログイン テーブルを作成しました。しかし、ログインが誰に接続されているかを知る必要があるため、個人または組織への参照が必要です。
次のクラスを考えてみましょう (簡略化)。
public class Login
{
public string Username {get; set;}
public string Password {get;set;}
}
public class LoginPerson : Login
{
public Person Person {get;set;}
}
public class LoginOrg : Login
{
public Organization Organization {get;set;}
}
public class Person
{
public LoginPerson LoginPerson {get;set;}
//Lots of other properties. Removed for simplicity
}
public class Organization
{
public LoginOrg LoginOrg {get;set;}
//Lots of other properties. Removed for simplicity
}
個人構成は次のように設定されます。
public class PersonConfiguration : EntityTypeConfiguration<Person>
{
public PersonConfiguration()
{
HasRequired(p => p.LoginPerson).WithRequiredPrincipal(p => p.Person);
}
}
まず、これがうまくいきません。「System.Data.EntityCommandCompilationException: System.Data.EntityCommandCompilationException: コマンド定義の準備中にエラーが発生しました。詳細については内部例外を参照してください。 ---> System.Collections.Generic.KeyNotFoundException: The given key was辞書に載っていない..」だから私の最初の質問は、なぜこれがうまくいかないのですか? 2 番目の質問は、この種の継承に最適な戦略はどれかということです。TPT、TPH、または TPC?