![](/img/trans.png)
[英]c# WPF bind combobox to TPH in Entity Framework code first using LINQ
[英]C#, Entity framework, TPH
我对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);
}
}
我总是收到以下错误:
---错误:在模型生成过程中检测到一个或多个验证错误:
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. ---
这是堆栈跟踪:
未处理的异常:System.Data.Entity.ModelConfiguration.ModelValidationException:在模型生成过程中检测到一个或多个验证错误:
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.
在C:\\ Projects_PrismaLoader \\ Prisma.Load er \\ PrismaLoader.cs:第95行在Prisma.Loader.PrismaLoader.Init()在C:\\ Projects_PrismaLoader.Load(布尔快速)在95: PrismaLoader.cs:第32行位于C:\\ Projects_PrismaLoader \\ Pri sma.Loader \\ Program.cs:第113行中Prisma.Loader.Program.Main(String [] args)
在这种情况下,堆栈跟踪并不是真的有用(似乎...)
有谁知道我犯了一个错误? 我一直在寻找一天...
我相信您需要将StartDate和EndDate虚拟化? Edm试图覆盖功能,但由于它们是密封的,因此无法覆盖它们,因此会在IL中复制它们吗?
解决
看来问题出在PartialDate类。 它必须带有[ComplexType]批注。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.