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.ModelValidationExcept ion: одна или несколько ошибок проверки были обнаружены во время генерации модели:
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.
в Prisma.Loader.PrismaLoader.Init() в C:\Projects_PrismaLoader\Prisma.Load er\PrismaLoader.cs: строка 95 в Prisma.Loader.PrismaLoader.Load(логическое быстрое) в C: \ Projects_PrismaLoade r \ Prisma PrismaLoader.cs: строка 32 в Prisma.Loader.Program.Main(String[] args) в C:\Projects_PrismaLoader\Pri sma.Loader\Program.cs: строка 113
В этом случае трассировка стека не очень полезна (кажется...)
У кого-нибудь есть идея, где я допустил ошибку? Я искал день сейчас...
2 ответа
Постановили
Кажется, что проблема заключалась в классе PartialDate. Он должен быть аннотирован аннотацией [ComplexType].
Я считаю, что вы должны сделать StartDate и EndDate виртуальными? Эдм пытается переопределить функциональность, но поскольку они запечатаны, он не может переопределить их, поэтому дублирует их в IL?