35 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C#
		
	
	
			
		
		
	
	
			35 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			C#
		
	
	
| using IRaCIS.Core.Domain.Models;
 | |
| using Microsoft.EntityFrameworkCore;
 | |
| using Microsoft.EntityFrameworkCore.Metadata.Builders;
 | |
| 
 | |
| 
 | |
| namespace IRaCIS.Core.Infra.EFCore.EntityConfigration
 | |
| {
 | |
|     public class SubjectConfigration : IEntityTypeConfiguration<Subject>
 | |
|     {
 | |
|        
 | |
| 
 | |
|         public void Configure(EntityTypeBuilder<Subject> builder)
 | |
|         {
 | |
|             // 从 Subject  到 TrialSiteUserList   会用两个建
 | |
|             //builder
 | |
|             //.HasMany(s => s.TrialSiteUserList)
 | |
|             //.WithOne(c => c.Subject)
 | |
|             //.HasForeignKey(s => new { s.TrialId, s.SiteId })
 | |
|             //.HasPrincipalKey(c => new { c.TrialId, c.SiteId });
 | |
| 
 | |
|             // 受试者 在项目中只有一个site  获取 TrialSiteCode  用两个键
 | |
|             builder
 | |
|             .HasOne(s => s.TrialSite)
 | |
|             .WithMany(c => c.SubjectList)
 | |
|             .HasForeignKey(s => new { s.TrialId, s.SiteId })
 | |
|             .HasPrincipalKey(c => new { c.TrialId, c.SiteId });
 | |
| 
 | |
|             //不能同时配置一对多 和一对一 但是有时表要存储多的最新的  比如受试者 最新的访视  在这里要显示配置
 | |
|             builder.HasOne(s => s.LatestSubjectVisit);
 | |
|             builder.HasOne(s => s.FinalSubjectVisit);
 | |
|             builder.HasMany(s => s.SubjectVisitList).WithOne(sv => sv.Subject);
 | |
|         }
 | |
|     }
 | |
| }
 |