using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace IRaCIS.Core.Test.CodeFirstTest.MSSQL { public class SubjectConfigration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { //不能同时配置一对多 和一对一 但是有时表要存储多的最新的 比如受试者 最新的访视 在这里要显示配置 builder.HasOne(s => s.LatestSubjectVisit); builder.HasOne(s => s.FinalSubjectVisit); builder.HasMany(s => s.SubejectVisitList).WithOne(sv => sv.Subject); } } public class TestOneConfigration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.HasOne(s => s.LatestTestMany).WithMany().HasForeignKey(t=>t.LatestTestManyId); builder.HasOne(s => s.FinalTestMany).WithMany().HasForeignKey(t => t.FinalTestManyId); builder.HasMany(s => s.TestManyList).WithOne(sv => sv.TestOne).HasForeignKey(t => t.TestOneId); } } }