简体   繁体   English

实体框架TPH创建多个ID列

[英]Entity Framework TPH creating multiple ID columns

I have the following: 我有以下几点:

class Employee {
 [Key]
 public int EmployeeID {get;set;}
 public List<TimeSensitiveData> JobTitle {get;set;}
 public List<TimeSensitiveData> Department {get;set;}
 public List<TimeSensitiveData> OfficeLocation {get;set;}
}

abstract class TimeSensitiveData {
 [Key]
 public int TimeSensitiveDataID {get;set;}
 public string Value1 {get;set;}
 public DateTime Date {get;set;}
}

class JobTitle : TimeSensitiveData {}
class Department : TimeSensitiveData {}
class OfficeLocation : TimeSensitiveData {}

seed method looks something like this: 种子方法看起来像这样:

seed () {
 List<TimeSeriesData> oflc = new List<TimeSeriesData>();
            TimeSeriesData oflc2 = new OfficeLocation();
            oflc2.Value1 = "New York";
            oflc.Add(oflc2); 
 List<TimeSeriesData> dpt = new List<TimeSeriesData>();
            TimeSeriesData dpt2 = new Department();
            dpt2.Value1 = "New York";
            dpt.Add(dpt2); 
  List<TimeSeriesData> jt = new List<TimeSeriesData>();
            TimeSeriesData jt2 = new JobTitle();
            jt2.Value1 = "New York";
            jt.Add(jt2);

 var Employees = new List<Employee> {
  new Employee{JobTitle=jt,Department=dpt,OfficeLocation=oflc},

 } 

}

when I seed the database with employees it creates an employees table and a TimeSensitiveData table. 当我为雇员添加数据库种子时,它将创建一个雇员表和一个TimeSensitiveData表。 In the TimeSensitiveData table there is a Discriminator column (which I know what it's doing) but there are also multiple Employee_EmployeeID columns. 在TimeSensitiveData表中,有一个Discriminator列(我知道它在做什么),但也有多个Employee_EmployeeID列。 Actually, it seems like its creating one for every complex object that extends TimeSensitiveData. 实际上,似乎为扩展TimeSensitiveData的每个复杂对象都创建了一个对象。

so the TimeSensitiveData table looks kind of like this 所以TimeSensitiveData表看起来像这样

TimeSensitiveDataID  Value1  Date  Discriminator  Employee_EmployeeID Employee_EmployeeID1 Employee_EmployeeID2
1                    xx      date  JobTitle       NULL                NULL(or value)       NULL
2
etc..
etc..

I'm not sure why this is happening, any ideas? 我不确定为什么会这样,有什么想法吗?

should I make the Lists in the employee model not TimeSensitiveData type lists? 我应该使雇员模型中的列表不是TimeSensitiveData类型列表吗? should they be concrete class type lists? 它们应该是具体的类类型列表吗?

[InverseProperty]部分修复了它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM