0
asp core 2.0으로 언어 사전을 개발 중입니다. 내 데이터베이스를 올바르게 디자인하는 방법에 대해 궁금합니다. 비슷한 질문을 보니 : How to design a database for translation dictionary?. 하나의 Entity Framework 핵심 테이블에 두 개의 외래 키
나는 다음 그림에서와 같이 데이터베이스를 만들하기로 결정database structure that i wanna realize in ef core
하지만 난 엔티티 프레임 워크 코어 2.0이 구조를 실현하는 방법을 모르겠어요.
워드 엔티티
public class Word
{
public Word()
{
Translations = new HashSet<Translation>();
}
[Key]
public Guid WordId { get; set; }
[Required]
public Guid LangCodeId { get; set; }
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Usage",
"CA2227:CollectionPropertiesShouldBeReadOnly")]
public virtual ICollection<Translation> Translations { get; set; }
}
번역 엔티티
public class Translation
{
[Key]
public Guid TranslationId { get; set; }
public Guid WordId1 { get; set; }
public Guid WordId2 { get; set; }
//[ForeignKey("WordId1,WordId2")]
public Word Words { get; set; }
}
유창 API
modelBuilder.Entity<Translation>()
.HasOne(w => w.Words)
.WithMany(m => m.Translations)
.HasForeignKey(fk => new { fk.WordId1, fk.WordId2 });
내가 마이그레이션을 추가하려고하면, 나는 오류 얻을 :
The relationship from 'Translation.Words' to 'Word.Translations' with
foreign key properties {'WordId1' : Guid, 'WordId2' : Guid} cannot target
the primary key {'WordId' : Guid} because it is not compatible. Configure
a principal key or a set of compatible foreign key properties for this
relationship.
을