0

我对 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 中的 Prisma.Loader.PrismaLoader.Init():第 95 行在 C:\Projects_PrismaLoader\Prisma.Loader\ 中的 Prisma.Loader.PrismaLoader.Load(Boolean quick) PrismaLoader.cs:C:\Projects_PrismaLoader\Prisma.Loader\Program.cs 中 Prisma.Loader.Program.Main(String[] args) 的第 32 行:第 113 行

在这种情况下,堆栈跟踪并不是很有用(似乎......)

有谁知道我在哪里犯了错误?我已经找了一天了...

4

2 回答 2

0

我相信您需要将 StartDate 和 EndDate 设为虚拟?Edm 正在尝试覆盖该功能,但因为它们是密封的,所以它不能覆盖它们,所以它在 IL 中复制它们?

于 2012-04-11T13:24:41.947 回答
0

解决

似乎问题出在 PartialDate 类上。它必须使用 [ComplexType] 注释进行注释。

于 2012-04-13T06:31:54.560 回答