코드에 먼저 매핑하려는 복잡한 데이터베이스가 있지만 두 개의 별도 클래스로 분할해야하는 테이블에 문제가 있습니다.EF 코드 첫 번째 여러 클래스를 한 테이블에 매핑
Site
----
Id
Name
Person
------
Id
Name
Dob
Address
Rank
Age
SiteId
PersonRoleLink
--------------
PersonId
RoleId
Role
----
Id
Name
는 기본적으로 사이트가 많은 사람들을 가지고 있으며, 각 사람이 많은 역할을 할 수 있습니다 : 다음과 같이 테이블 구조의
기본 예입니다.
사람의 역할에 따라 채워지는 속성이 결정됩니다. 다음과 같이
이상적으로 나는 클래스 구조를 싶습니다Customer
,
Employee
및
Manager
모두가
Person
테이블에서 와서
PersonRoleLink
테이블의 관련 링크에 의존
public class Site {
public int Id { get; set; }
public string Name { get; set; }
public virtual ICollection<Customer> Customers { get; set; }
public virtual ICollection<Employee> Employees { get; set; }
public virtual ICollection<Manager> Managers { get; set; }
}
public class PersonBase {
public int Id { get; set; }
public string Name { get; set; }
public virtual Site Site { get; set; }
}
public class Customer : PersonBase {
public string Name { get; set; }
public DateTime Dob { get; set; }
}
public class Employee: PersonBase {
public int Age { get; set; }
}
public class Manager: PersonBase {
public int Rank { get; set; }
}
.
그래서 반환 Person
테이블에 Site.Managers
행 뭔가를 호출 할 때 올바른 SiteId와 '관리자'
라는 Role
에 대한 링크를 가진 사람이 첫 번째 코드에서이 구조 가능하다? 그렇다면이 매핑이 어떻게 이루어지며 그렇지 않은 경우이 구조에 대한 실행 가능한 대안이 있습니까?
감사
위대한 답변, 감사합니다. – lancscoder