엔티티 프레임 워크의 두 개의 다른 테이블에 단일 엔티티를 매핑하는 데 어려움을 겪고 있습니다.엔티티 프레임 워크 - 여러 테이블에 단일 엔티티
필자는 회사의 많은 응용 프로그램에서 사용하는 하나의 주 테이블을 가지고 있으므로이 테이블을 변경하고 싶지는 않습니다.
새 응용 프로그램에서 우리가 추가 할 기능 중 일부를 지원하기 위해 몇 개의 열이 더 필요했습니다. 이 테이블 모두 기록이있을 때 나는이 두 테이블에 정보를 저장하는 하나의 엔티티 모델을 만든
, 그것은 잘 작동
그러나 역사적 기록이를 위해 (기본 키와 외래 키에 의해 관련) 새 테이블에는 연관된 레코드가 없으며 엔티티 집합을 가져올 수 없습니다.
다음은 코드 스 니펫입니다.
public class ModelTable
{
public string PatientID { get; set; }
public string Diagnosis1 { get; set; }
public string Diagnosis2 { get; set; }
public string Diagnosis3 { get; set; }
public string Diagnosis4 { get; set; }
public string Diagnosis5 { get; set; }
public string Diagnosis6 { get; set; }
public string Diagnosis7 { get; set; }
public string Diagnosis8 { get; set; }
}
public class ModelTableMap : EntityTypeConfiguration<ModelTable>
{
public ModelTableMap()
{
//Table1
this.Map(model =>
{
model.Properties(table1 => new
{
table1.Diagnosis1,
table1.Diagnosis2,
table1.Diagnosis3,
table1.Diagnosis4,
table1.Diagnosis5,
table1.Diagnosis6
});
model.ToTable("Table1");
});
//Optional Table
this.Map(model =>
{
model.Properties(table2 => new
{
table2.Diagnosis7,
table2.Diagnosis8,
});
model.ToTable("Table2");
});
this.HasKey(type => type.PatientID);
this.Property(type => type.PatientID).IsRequired().HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);
this.Property(type => type.Diagnosis1).HasColumnName("Diag1");
this.Property(type => type.Diagnosis1).HasColumnName("Diag2");
this.Property(type => type.Diagnosis1).HasColumnName("Diag3");
this.Property(type => type.Diagnosis1).HasColumnName("Diag4");
this.Property(type => type.Diagnosis1).HasColumnName("Diag5");
this.Property(type => type.Diagnosis1).HasColumnName("Diag6");
this.Property(type => type.Diagnosis1).HasColumnName("Diag7");
this.Property(type => type.Diagnosis1).HasColumnName("Diag8");
}
}
이 두 테이블을 두 개의 다른 POCO 클래스로 나누고 relationshipt를 지정하면 올바르게 작동합니다.
하지만 기능적으로 동일한 테이블이므로 Single Entity를 사용하여이 작업을 수행하고 싶습니다.
아무런 지침을 제공하지 않거나 잘못하고 제발 내 영어 실력을 향상시키는 것이 좋지 않습니다. 현재 EF 버전
감사 사티시
응답 해 주셔서 감사합니다. 그래서 나는이 경우에 두 개의 분리 된 실재물과 함께 살아야만한다고 생각합니다. – Sathish