次のようなDB構造があります。
create table Person (
ID bigint identity not null,
FirstName varchar(100),
LastName varchar(100),
-- etc... lot's of generic fields that apply to a person, e.g. phone, address
)
create table Teacher (
ID bigint identity not null,
PersonID bigint not null,
EmploymentDate date,
-- plus a bunch of other teacher-specific fields
)
create table Student (
ID bigint identity not null,
PersonID bigint not null,
EnrollmentDate date,
-- plus a bunch of student-specific fields
)
create table SystemUser (
ID bigint identity not null,
PersonID bigint not null,
UserName varchar(50) not null,
-- plus any user specific fields
)
と他のすべてのフィールドの関係Personは 1 -> 0:1 であり、 の各「サブクラス」はPersonに一意のキーを持っていますPersonID。Aは aまたは aSystemUserと同じ人物である場合があります。実際、3 つすべてを備えている人がいる可能性もあります。TeacherStudent
Teacherここで、 、Studentおよびを表す EF エンティティを作成したいと思います。SystemUserこれらはそれぞれ (1 位) から実際に継承するPersonか、少なくともPersonクラス内のフィールドを組み込み、両方の基になるテーブルに暗黙的にマッピングします。
同じ主キーを共有している例をオンラインでたくさん見つけましたが、同じ主キーを共有していない、つまりPersonID派生テーブルがテーブルにマップさIDれている例はありませんPerson。
どうやってやるの?