我有一個TPH映射的問題。 這裏是類:C#,實體框架,TPH
摘要服務(基類)
[Table("Services")]
public abstract class AbstractService : IAuditedObject
{
public int Id { get; set; }
[DisplayName("Receiver Site")]
public int? TargetSiteId { get; set; }
[DisplayName("Receiver Site")]
public virtual Site TargetSite { get; set; }
[DisplayName("Start Date")]
public PartialDate StartDate { get; set; }
[DisplayName("End Date")]
public PartialDate EndDate { get; set; }
[DisplayName("Study")]
public int? StudyId { get; set; }
[DisplayName("Study")]
public virtual Study Study { get; set; }
}
混凝土服務
public class AssociatedStaffService : AbstractService
{
[DisplayName("Person")]
[Required]
public int? SourcePersonId { get; set; }
[DisplayName("Person")]
public virtual Person SourcePerson { get; set; }
[DisplayName("Service")]
[Required]
public int? RoleId { get; set; }
[DisplayName("Service")]
public virtual AssociatedStaffServiceCLI Role { get; set; }
[DisplayName("Department")]
public string Department { get; set; }
public bool IsActive()
{
return this.SourcePerson != null && this.TargetSite != null && this.SourcePerson.IsActive() && this.TargetSite.IsActive() && this.Study != null && (this.EndDate == null || this.EndDate.Date == null || this.EndDate.Date > DateTime.Now);
}
}
public class EthicCommitteeService : AbstractService
{
[DisplayName("Site")]
[Required]
public int? SourceSiteId { get; set; }
[DisplayName("Site")]
public virtual Site SourceSite { get; set; }
[DisplayName("Central")]
public bool? IsCentral { get; set; }
public bool IsActive()
{
return this.Study != null && this.TargetSite != null && this.SourceSite != null && this.TargetSite.IsActive() && this.SourceSite.IsActive() && (this.EndDate == null || this.EndDate.Date == null || this.EndDate.Date > DateTime.Now);
}
}
public class ParticipatingService : AbstractService
{
public const string AUTHORIZATION_DATE = "AuthorizationDate";
public const string IS_NATIONAL_COORDINATOR = "IsNationalCoordinator";
[DisplayName("Person")]
[Required]
public int? SourcePersonId { get; set; }
[DisplayName("Person")]
public virtual Person SourcePerson { get; set; }
[DisplayName("Service")]
[Required]
public int? RoleId { get; set; }
[DisplayName("Service")]
public virtual ParticipatingServiceCLI Role { get; set; }
[DisplayName("Department")]
public string Department { get; set; }
public int? RegInvestigatorFormId { get; set; }
public PartialDate AuthorizationDate { get; set; }
public bool? IsNationalCoordinator { get; set; }
public bool IsActive()
{
return this.SourcePerson != null && this.TargetSite != null && this.SourcePerson.IsActive() && this.TargetSite.IsActive() && this.Study != null && (this.EndDate == null || this.EndDate.Date == null || this.EndDate.Date > DateTime.Now);
}
}
public class ExternalService : AbstractService
{
[DisplayName("Person")]
[Required]
public int? SourcePersonId { get; set; }
[DisplayName("Person")]
public virtual Person SourcePerson { get; set; }
[DisplayName("Service")]
[Required]
public int RoleId { get; set; }
[DisplayName("Service")]
public virtual ExternalServiceCLI Role { get; set; }
[DisplayName("Department")]
public string Department { get; set; }
public bool IsActive()
{
return this.SourcePerson != null && this.TargetSite != null && this.SourcePerson.IsActive() && this.TargetSite.IsActive() && this.Study != null && (this.EndDate == null || this.EndDate.Date == null || this.EndDate.Date > DateTime.Now);
}
}
public class StudyTeamService : AbstractService
{
[DisplayName("Person")]
[Required]
public int? SourcePersonId { get; set; }
[DisplayName("Person")]
public virtual Person SourcePerson { get; set; }
[DisplayName("Service")]
[Required]
public int? RoleId { get; set; }
[DisplayName("Service")]
public virtual StudyTeamServiceCLI Role { get; set; }
[DisplayName("Department")]
public string Department { get; set; }
public bool IsActive()
{
return this.SourcePerson != null && this.TargetSite != null && this.SourcePerson.IsActive() && this.TargetSite.IsActive() && this.Study != null && (this.EndDate == null || this.EndDate.Date == null || this.EndDate.Date > DateTime.Now);
}
}
我總是得到以下錯誤:
--- ERROR: One or more validation errors were detected during model generation:
System.Data.Edm.EdmProperty: Name: Each property name in a type must be unique. Property name 'StartDate' is already defined. System.Data.Edm.EdmProperty: Name: Each property name in a type must be unique. Property name 'EndDate' is already defined. ---
這裏是堆棧跟蹤:
Unhandled Exception: System.Data.Entity.ModelConfiguration.ModelValidationExcept ion: One or more validation errors were detected during model generation:
System.Data.Edm.EdmProperty: Name: Each property name in a type must be unique. Property name 'StartDate' is already defined. System.Data.Edm.EdmProperty: Name: Each property name in a type must be unique. Property name 'EndDate' is already defined.
at Prisma.Loader.PrismaLoader.Init() in C:\Projects_PrismaLoader\Prisma.Load er\PrismaLoader.cs:line 95 at Prisma.Loader.PrismaLoader.Load(Boolean quick) in C:\Projects_PrismaLoade r\Prisma.Loader\PrismaLoader.cs:line 32 at Prisma.Loader.Program.Main(String[] args) in C:\Projects_PrismaLoader\Pri sma.Loader\Program.cs:line 113
堆棧跟蹤是不是在這種情況下,真正有用的(似乎...)
有誰有,我犯了一個錯誤的想法?我一直在尋找一天...
你能告訴我什麼是'IAuditedObject'嗎? – Likurg 2012-04-11 13:22:16
IAuditedObject是一個空的接口,它允許我們記錄在對象上完成的每個更改,以便我們可以隨時重新創建它。 (= Trailed對象) – Whoami 2012-04-11 13:37:20